⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)
Weird "QApplication before qwidget" problem
I have a working desktop application developed in Qt 5.3.1, under Win8.1 64bit OS. To help others contribute in the project, I made a virtual machine with exactly the same settings as my own, except the OS is Win7 in the virtual machine. The app uses opencv 2.4.9, PCL and all its dependencies, but they are exactly all the same. When I managed to create the development enviroment, I pulled the source from git, and got an error "must construct qapplication before qwidget" after building, and the application crashed. The exact same code works on my laptop even after a clean build. I have read about this error and its fixes but as I said, it works without issues locally, the error comes in the VM.
This could be some kind of black magic, and I have no idea how to fix it. Does anyone have any suggestions?
Thank you in advance,
Hard to say without seeing the code. At least the main() function.
Most likely you actually created a widget before creating a QApplication or you mixed debug and release dlls (which seems even more likely in the scenario you described).
My main function is:
int main(int argc, char *argv)
QApplication a(argc, argv);
QFile File("ScStyleSheet.qss"); File.open(QIODevice::ReadOnly | QIODevice::Text); QString StyleSheet = QLatin1String(File.readAll()); a.setStyleSheet(StyleSheet); MainWindow w; w.setWindowFlags(Qt::Window | Qt::FramelessWindowHint); // | Qt::CustomizeWindowHint w.showMaximized(); return a.exec();
While debugging, everything is fine until the MainWindow w; line.
What do you actually mean by mixing debug and release dlls?
You can build Qt in release or debug mode which (by default) produces Qt5ModuleName.dll and QtModuleNamed.dll (notice the d). It's the same with the .lib files for linking.
If you only have the release version and try to link to it from a debug version of your app strange things will happen and some people reported in the past that this message is one of the symptoms.
I have installed the "5.3 msvc2013 opengl 64" version downloaded from here. It contains both debug and release libraries. I tried one example in both debug and release modes and it worked fine. While building PCL, I had to set Qt debug&release libraries manually with CMake, but there were no mistakes. Commenting out the MainWindow related lines, the app starts and does not crash, the QApplication is instantiated. I have no idea about the error. Can I manually tell CMake to only use dlls of the debug or release version?
I managed to run the app by building in release mode, thanks for helping me!