PDA

View Full Version : Qwt and Qwtpolar : "Qwidget: Must construct a QApplication before a QWidget"



plb29n
17th December 2014, 18:20
Hi,
I am just new to Qt programming and try to use both Qwt (6.1.1) and Qwtpolar (1.1.1) libs on windows XP under Qt5.2.1 (mingw48_32)
On the hereafter example, the release version works properly but I can't make the debug version work.
I've got the following message : "Qwidget: Must construct a QApplication before a QWidget"
I've checked with the debugger that it fails when it tries to create the QwtPolarPlot instance.
As the objects files are created within the ./debug directrory I know that the CONFIG test works fine
and I properly refer to the debug libraries versions -- qwtd and qwtpolard --
moreover, there are also properly referred in the Makefile.debug
These libs were created with their default .pro files within QtCreator.

Any idea ?


The .cpp file

MainWindow::MainWindow( QWidget *parent ):
QMainWindow( parent )
{
m_pCentralWidget = new QWidget(this);
setCentralWidget(m_pCentralWidget);

m_pPolarGraph = new QwtPolarPlot(m_pCentralWidget);
QGridLayout *pLayout = new QGridLayout(m_pCentralWidget);
pLayout->addWidget(m_pPolarGraph, 1, 0);
}


int main( int argc, char **argv )
{
QApplication a( argc, argv );
MainWindow mainWindow;
mainWindow.show();
return a.exec();
}



The .Pro file

TARGET = trial1
QT += widgets
MOC_DIR = moc
DEFINES += QWT_DLL QWT_POLAR_DLL

QWT_ROOT = C:\LocalApplications\qwt-6.1.1
QWT_LIBS = -L$${QWT_ROOT}\lib
QWT_INCLUDES = $${QWT_ROOT}\src

QWT_POLAR_ROOT = C:\LocalApplications\qwtpolar-1.1.1
QWT_POLAR_LIBS = -L$${QWT_POLAR_ROOT}\lib
QWT_POLAR_INCLUDES = $${QWT_POLAR_ROOT}\src

INCLUDEPATH += $${QWT_POLAR_INCLUDES} $${QWT_INCLUDES}
LIBS += $${QWT_LIBS} $${QWT_POLAR_LIBS}

CONFIG(debug, debug|release) {
DESTDIR = ./debug
LIBS += -lqwtd -lqwtpolard
OBJECTS_DIR =./debug
} else {
DESTDIR = ./release
LIBS += -lqwt -lqwtpolar
OBJECTS_DIR =./release
}

SOURCES += \
main.cpp

Uwe
17th December 2014, 22:00
This message often indicates that you are mixing libs/apps build with release and debug.

Uwe

plb29n
18th December 2014, 08:17
Hi Uwe,

Thanks a lot for your reply. Following it, I checked with DepedencyWalker the dependencies of qwtpolard.dll and saw that
it depended on qwt.dll (instead of qwtd.dll). The reason is the following : Previously, in order to compile the qwtpolar libraries
under QtCreator I had to add qwt paths (lib and include) and library name to the qwtpolar/src/src.pro file and forgot to make
the distinction between release and debug mode.

When I do it in the right way (using CONFIG(debug, debug|release) ... ) it works perfectly : qwtpolard.dll depends on qwtd.dll
and my application runs in both modes.

The question is now : why do I have to add the dependencies to qwt (lib and include paths) when I try to compile qwtpolar
whereas I use the default .pro files delivered with qwtpolar1.1.1 ?

Thanks again.

Uwe
18th December 2014, 08:33
You didn't install qwtpolar properly - instead you are trying to build against something left over in the build directory. Once having qwtpolar installed, you will see, that qwtpolar.prf ( CONFIG += qwtpolar ) is the one for building applications.
Have a look at http://qwt.sourceforge.net/qwtinstall.html. The concepts are the same for qwtpolar then.

Putting the sources of qwt and qwtpolar and your application into one project is not the officially supported way and then you have to be able to ship around those issues yourself.

Uwe

plb29n
18th December 2014, 10:02
Ok I understand but I actually did not put the sources into a single project.

First : I downloaded qwt and used the qwt.pro file to generate qwt.dll and qwtd.dll (/lib directory)


Second : I downloaded qwtpolar and used the qwtpolar.pro file to generate qwt.dll and qwtd.dll (/lib directory) -- This is where I had to modify the qwtpolar/src/src.pro file to be able to go through compilation without errors (this is also where I must miss something ...)


Third : Once all dlls are generated, I created my own application (with its own sources) that uses both qwt and qwtpolar libraries.
(In the previously given example I refer to the src directories of qwt and qwtpolar only to get an access to their headers, but I do
not address directly their .cpp files in my application)


Sorry I do it again since their are mistakes in the previous answer....

Ok I understand but I actually did not put the sources into a single project.

First : I downloaded qwt and used the qwt.pro file to generate qwt.dll and qwtd.dll (/lib directory)


Second : I downloaded qwtpolar and used the qwtpolar.pro file to generate qwtpolar.dll and qwtpolard.dll (/lib directory) -- This is where I had to modify the qwtpolar/src/src.pro file to be able to go through compilation without errors (this is also where I must miss something ...)


Third : Once all dlls are generated, I created my own application (with its own sources) that uses both qwt and qwtpolar libraries.
(In the previously given example I refer to the src directories of qwt and qwtpolar only to get an access to their headers, but I do
not address directly their .cpp files in my application)

Uwe
18th December 2014, 11:38
Ok I understand but I actually did not put the sources into a single project.

First : I downloaded qwt and used the qwt.pro file to generate qwt.dll and qwtd.dll (/lib directory)

Next step would be to install qwt. Then building qwtpolar would be against the properly installed qwt - not against the source tree, where you have built qwt.

Uwe

plb29n
18th December 2014, 21:01
Ok,
Thanks a lot for your help Uwe.