Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Weird "QApplication before qwidget" problem

    General and Desktop
    2
    6
    1188
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F
      fandras90 last edited by

      Hi everyone,

      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,
      András

      1 Reply Last reply Reply Quote 0
      • Chris Kawa
        Chris Kawa Moderators last edited by

        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).

        1 Reply Last reply Reply Quote 0
        • F
          fandras90 last edited by

          Hi,
          My main function is:

          @#include "ScView/wndMain.h"
          #include <QFile>
          #include <QApplication>
          #include <QMainWindow>

          #include "Engine.h"

          int main(int argc, char *argv[])
          {
          QApplication a(argc, argv);

          QFile File&#40;"ScStyleSheet.qss"&#41;;
          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&#40;&#41;;
          

          }@

          While debugging, everything is fine until the MainWindow w; line.
          What do you actually mean by mixing debug and release dlls?

          1 Reply Last reply Reply Quote 0
          • Chris Kawa
            Chris Kawa Moderators last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • F
              fandras90 last edited by

              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?

              1 Reply Last reply Reply Quote 0
              • F
                fandras90 last edited by

                I managed to run the app by building in release mode, thanks for helping me!

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post