|
本帖最后由 bdbox 于 2009-10-23 09:00 编辑
以下是我改造的,集成在自己写的qt应用程序中:
MyWidget.h文件:-
- #include <QtCore/QString>
- #include <QtCore/QTimer>
- #include <QtGui/QKeyEvent>
- #include <QtGui/QApplication>
- #include <QtOpenGL/QGLWidget>
- #include <QtGui/QMainWindow>
- #include <QtGui/QMdiSubWindow>
- #include <QtGui/QMdiArea>
- #include <QtGui/QHBoxLayout>
- class MyWidget : public QWidget
- {
- public:
- MyWidget(QWidget *parent);
- };
复制代码 AdapterWidget.cpp文件改造部分:-
- ...
- #include "MyWidget.h"
- ...
- MyWidget::MyWidget(QWidget *parent = 0)
- {
- setGeometry(100, 100, 800, 600);
- osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile("cow.osg");
- ViewerQT *viewerWindow = new ViewerQT;
- viewerWindow->setCameraManipulator(new osgGA::TrackballManipulator);
- viewerWindow->setSceneData(loadedModel.get());
- QHBoxLayout *mainLayout = new QHBoxLayout;
- mainLayout->addWidget(viewerWindow);
- setLayout(mainLayout);
- }
- ...
复制代码 调用部分:-
- #include "qttest7.h"
- #include "MyWidget.h"
- QtTest7:tTest7(QWidget *parent, Qt::WFlags flags)
- : QMainWindow(parent, flags)
- {
- ui.setupUi(this);
- MyWidget* widget = new MyWidget();
- //ui.centralWidget = widget;
- }
- QtTest7::~QtTest7()
- {
- }
复制代码 当运行到MyWidget* widget = new MyWidget();时程序自动退出。没有报错。调试进去是:ViewerQT *viewerWindow = new ViewerQT;句就自动退出了。
谢谢~! |
|