I have already posted this in the OSG mailing list, but the mailing list seems to be a bit slow.
Anyway, I'm trying to modify the osgViewerQt example by adding a new class of my own that will contain the viewer. The design is:
The project compiles, but when I execute it, I get an error:
QWidget: Must construct a QApplication before a QPaintDevice*
If I remove the Q_OBJECT line, the signal and the slot from wrapper.h and compile the files from the terminal using
g++ -IE:/osg-3.0.1/install/include -LE:/osg-3.0.1/install/bin -IC:/Qt64/4.8/include -LC:/Qt64/4.8/bin -losgViewer -lOpenThreads -losgDB -losg -losgGA -losgQt -lQtCore4 -lQtGui4 prueba_qt.cpp
I can execute the app.
Can you please tell me what can I do to make this work? I've struggling all morning but couldn't find the solution.
Thanks for your time!
PS: SO is Windows 7 64 bits # MingW compiler # Qt 4.8 # OSG 3.0.1
PS2: Here're the files I used in this project, including the pro file from qmake:
wrapper.h
#ifndef Wrapper_hpp
#define Wrapper_hpp
#include "viewer.h"
#include <QtGui/QMainWindow>
#include <QtGui/QDockWidget>
class Wrapper: public QMainWindow {
Q_OBJECT
private:
ViewerWidget* view;
QDockWidget* dock;
public:
Wrapper(void) {
view = new ViewerWidget();
dock = new QDockWidget;
dock->setWidget( view );
dock->setGeometry( 100, 100, 800, 600 );
dock->setAllowedAreas(Qt::RightDockWidgetArea);
addDockWidget(Qt::RightDockWidgetArea, dock);
dock->show();
}
void Do(void) { view->Do(); }
void Add(void) { view->Add(); }
virtual ~Wrapper(void) {}
public slots:
void MySlot(void) {}
signals:
void MySignal(void);
};
#endif
wrapper.cpp
(This exists only because I read in the Qt forum that moc can only parse cpp files and thus one is needed for the signal/slot mechanism.)
#include "wrapper.h"
Wrapper::Wrapper(void) {
view = new ViewerWidget();
// view->setGeometry( 100, 100, 800, 600 );
dock = new QDockWidget;
dock->setWidget( view );
dock->setGeometry( 100, 100, 800, 600 );
dock->setAllowedAreas(Qt::RightDockWidgetArea);
addDockWidget(Qt::RightDockWidgetArea, dock);
dock->show();
}
prueba_qt.cpp
#include <QtGui/QApplication>
#include <iostream>
#include "wrapper.h"
int main( int argc, char** argv ) {
osg::ArgumentParser arguments(&argc, argv);
QApplication app(argc, argv);
Wrapper wrap;
wrap.resize(800,600);
wrap.setWindowTitle("Cow");
wrap.showNormal();
wrap.Do();
return app.exec();
}
prueba_qt.pro
######################################################################
# Automatically generated by qmake (2.01a) mar 12. mar 13:45:28 2013
######################################################################
QT += core gui
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += . E:/osg-3.0.1/install/include
LIBS += -LE:/osg-3.0.1/install/bin -losg -lOpenThreads -losgDB -losgGA -losgQt -losgViewer
# Input
HEADERS += viewer.h wrapper.h
SOURCES += prueba_qt.cpp wrapper.cpp
viewer.h: This is quite big, so I uploaded it to pastebin
EDIT #1
I have set OSG_NOTIFY_LEVEL to DEBUG_INFO and got this humongous output. The line with the error is:
FindFileInPath() : trying C:\cygwin\bin\osgPlugQWidget: Must construct a QApplication before a QPaintDevice
EDIT #2
The signal and slot were missing in the code. I have just added them to wrapper.h along with the call to Q_OBJECT.
After a little nap, I revised again the libraries used in the project. The problem was that some of those libraries were in debug mode and some in release mode. When using signals and slots, moc went crazy.
After building OSG debug libraries, I tried again my little example and worked.
So it's done!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With