QtTreePropertyBrowser runtime error: "QWidget: Must construct a QApplication before a QWidget"
-
int main(int argc, char *argv[]) { MyApp a(argc, argv); QtTreePropertyBrowser * p = new QtTreePropertyBrowser; return 0; }
built successfully, run time error:
QWidget: Must construct a QApplication before a QWidget
tried both debug & release versions of QtPropertyBrowserbtw, the QtPropertyBrowser examples with the lib work
version info:
Qt 5.12.0
QtCreator 4.8.0
QtPropertyBrowser head at https://github.com/qtproject/qt-solutions.git
kit MSVC2017 64bit -
What is MyApp object ? Looks like it is not inherited from QApplication ? Before constructing any QWidget based object, you must have QApplication created. In your case it not. Hence you have this run time error & application peacefully crashes.
-
What is MyApp object ? Looks like it is not inherited from QApplication ? Before constructing any QWidget based object, you must have QApplication created. In your case it not. Hence you have this run time error & application peacefully crashes.
@dheerendra said in QtTreePropertyBrowser runtime error: "QWidget: Must construct a QApplication before a QWidget":
What is MyApp object ?
class MyApp : public QApplication { Q_OBJECT public: explicit MyApp (int &argc, char **argv); signals: public slots: };
-
This seems to be ok. Event loop is not started. Can you add it ? a.exec() instead of return 0.
-
This seems to be ok. Event loop is not started. Can you add it ? a.exec() instead of return 0.
@dheerendra said in QtTreePropertyBrowser runtime error: "QWidget: Must construct a QApplication before a QWidget":
This seems to be ok. Event loop is not started. Can you add it ? a.exec() instead of return 0.
added
return a.exe();
, crashed before reaching here -
Instead of MyApp can you try creating the QApplication object ? Do you have any global object of QtTreePropertyBrowser somewhere else ?
-
Instead of MyApp can you try creating the QApplication object ? Do you have any global object of QtTreePropertyBrowser somewhere else ?
@dheerendra said in QtTreePropertyBrowser runtime error: "QWidget: Must construct a QApplication before a QWidget":
Instead of MyApp can you try creating the QApplication object ? Do you have any global object of QtTreePropertyBrowser somewhere else ?
tried, can't solve
when debugging, it can execute until the line of code to createQtTreePropertyBrowser
-
Strange. Can u just create qpushbutton object & see it works ? Comment ur treebrowser code.
-
Strange. Can u just create qpushbutton object & see it works ? Comment ur treebrowser code.
@dheerendra said in QtTreePropertyBrowser runtime error: "QWidget: Must construct a QApplication before a QWidget":
Strange. Can u just create qpushbutton object & see it works ? Comment ur treebrowser code.
everything else works
-
Hi,
Do you have any static QWiget object ?
-
If possible can you share your project bat pastebin or somewhere else ?
-
@jronald I hope in the constructor definition you are passing the parameter to QApplication.
MyApp (int &argc, char **argv) : QApplication(argc, argv)
{
...
} -
If possible can you share your project bat pastebin or somewhere else ?
@dheerendra said in QtTreePropertyBrowser runtime error: "QWidget: Must construct a QApplication before a QWidget":
If possible can you share your project bat pastebin or somewhere else ?
- create a new
Qt Widget Application
- modify .pro to add
INCLUDEPATH
andLIBS
forQtPropertyBrowser
- edit
MainWindow.cpp
#include "MainWindow.h" #include "ui_MainWindow.h" #include <QtTreePropertyBrowser> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { QtTreePropertyBrowser * p = new QtTreePropertyBrowser(this); ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; }
Application Output Window shows:
QWidget: Must construct a QApplication before a QWidget
- create a new
-
@jronald I hope in the constructor definition you are passing the parameter to QApplication.
MyApp (int &argc, char **argv) : QApplication(argc, argv)
{
...
}@Maaz-Momin said in QtTreePropertyBrowser runtime error: "QWidget: Must construct a QApplication before a QWidget":
@jronald I hope in the constructor definition you are passing the parameter to QApplication.
MyApp (int &argc, char **argv) : QApplication(argc, argv)
{
...
}sure, it's by default
-
@jronald Can you paste your MyApp.h and MyApp.cpp here. Also If possible your .pro file.
-
@jronald Can you paste your MyApp.h and MyApp.cpp here. Also If possible your .pro file.
@Maaz-Momin said in QtTreePropertyBrowser runtime error: "QWidget: Must construct a QApplication before a QWidget":
@jronald Can you paste your MyApp.h and MyApp.cpp here. Also If possible your .pro file.
I've created a new
Qt Widget Application
for testing. -
@jronald said in QtTreePropertyBrowser runtime error: "QWidget: Must construct a QApplication before a QWidget":
QtTreePropertyBrowser
Where did you get that class from ?
-
@jronald said in QtTreePropertyBrowser runtime error: "QWidget: Must construct a QApplication before a QWidget":
QtTreePropertyBrowser
Where did you get that class from ?
@SGaist said in QtTreePropertyBrowser runtime error: "QWidget: Must construct a QApplication before a QWidget":
Where did you get that class from ?
QtPropertyBrowser head at https://github.com/qtproject/qt-solutions.git
-
@jronald said in QtTreePropertyBrowser runtime error: "QWidget: Must construct a QApplication before a QWidget":
QtTreePropertyBrowser
Where did you get that class from ?
@SGaist said in QtTreePropertyBrowser runtime error: "QWidget: Must construct a QApplication before a QWidget":
@jronald said in QtTreePropertyBrowser runtime error: "QWidget: Must construct a QApplication before a QWidget":
QtTreePropertyBrowser
Where did you get that class from ?
Tried https://code.qt.io/qt-solutions/qt-solutions.git, to my surprise it works.
Thank you very much2 points to mention:
- debug/release must be matched for app and the lib
- clean before build (rebuild may be ok, not tried), or delete the build dir manully