c++ - Qt with qwt runtime error: QWidget: Must construct a QApplication before a QWidget -
i trying make app using qt 5.4.1(and qwt 6.1.2).here environment:
- windows 7 x64
- visual studio 2012
- qt5.4.1 static
- qwt6.1.2
and have built qwt qt static libs successfully. creat widget class inherited qwtplot,and creat mainwindow has object of widget. build project. however,there runtime error:qwidget: must construct qapplication before qwidget.
this widget class inherited qwtplot:
#pragma once #include <qwt/qwt_plot.h> #include <qwt/qwt_plot_curve.h> class drawwidget: public qwtplot { public: drawwidget(qwidget *parent ); ~drawwidget(void); };
drawwidget::drawwidget(qwidget *parent ) : qwtplot( parent ), carve(null) { }
and follow mainwindow class:
#ifndef mainwindow_h #define mainwindow_h #include "drawwidget.h" #include <qtwidgets/qmainwindow> class mainwindow : public qmainwindow { q_object public: mainwindow(qwidget *parent = 0); ~mainwindow(); private: drawwidget *drawwidget; }; #endif // mainwindow_h
mainwindow::mainwindow(qwidget *parent) :qmainwindow(parent) { qwidget *widget = new qwidget(this); this->setcentralwidget(widget); qhboxlayout *mainlayout = new qhboxlayout(widget); drawwidget = new drawwidget(widget); mainlayout->addwidget(drawwidget); centralwidget()->setlayout(mainlayout); }
and main.cpp:
#include "mainwindow.h" #include <qtwidgets/qapplication> #include <qtplugin> q_import_plugin(qwindowsintegrationplugin); int main(int argc, char *argv[]) { qapplication a(argc, argv); mainwindow w; w.resize(1000,600); w.show(); return a.exec(); }
i build project in release version.any idea? thank you!
i had same problem few weeks ago in case problem additional library. make sure got builds of additional library debug debug building , release release building. add additionallibrarydebug/bin folder path environment variable when build debug version , additionallibraryrelease/bin when build release version (not both in same time)
good luck :) solved problem on way. :)
Comments
Post a Comment