Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Strange crash in QApplication constructor
Forum Updated to NodeBB v4.3 + New Features

Strange crash in QApplication constructor

Scheduled Pinned Locked Moved Unsolved General and Desktop
crashqcoreapp
18 Posts 6 Posters 1.5k Views 2 Watching
  • 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.
  • Pl45m4P Offline
    Pl45m4P Offline
    Pl45m4
    wrote on last edited by
    #6

    @Jakob-Kenda

    I've tested it as well and experienced the same as @Christian-Ehrlicher ... worked for me on Windows with Qt6.8.
    (I didn't used pre-compiled headers, though)


    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

    ~E. W. Dijkstra

    1 Reply Last reply
    1
    • I Online
      I Online
      IgKh
      wrote on last edited by
      #7

      I second the two replies above. The stack trace makes no sense, although the code as written should be perfectly valid. I suspect that maybe in your precompiled headers, the definition of qApp macro is the one from qcoreapplication.h rather than the one from qapplication.h. Try changing from using precompiled header to normal include of <QApplication>?

      1 Reply Last reply
      2
      • J Offline
        J Offline
        Jakob Kenda
        wrote on last edited by Jakob Kenda
        #8

        Thank you for your replies. I'll just answer to all of you in one.

        @Pl45m4 The change makes no difference, the program still crashes in the same place. There are no issues on Windows for me either, only on Linux.

        @IgKh I know the stack trace makes no sense, that's why I'm writing on the forum. If I could've figured this out myself I wouldn't be here.
        I tried compiling without a PCH but the behaviour still stays the same. This is the modified code:

        #include "QtWidgets/qapplication.h"
        #include <iostream>
        
        static void use_qapp(QApplication* qApplication)
        {
          std::cout << qApp << '\n';
        }
        

        There's no change in the behaviour of the program.

        @Christian-Ehrlicher I'm building the application with CMake. RPATH is set to $ORIGIN and all the necessary Qt .so files copied to the same directory as the executable. Although debugging I set the LD_LIBRARY_PATH to the directory where Qt libraries were downloaded by the Qt Maintainance Tool, the behavoiur of the program was identical in both cases.
        I also tried debugging ld with LD_DEBUG=libs in case there was a problem with loading the wrong SO or loading the same SO twice but the outputs of both programs were identical up to the point where one crashed.

        I suspect the problems likely have something to do with putting the shared objects along with the executable, which is an unconventional approach on Linux, but I just can't figure out why that would be a problem.

        JonBJ I 2 Replies Last reply
        0
        • J Jakob Kenda

          Thank you for your replies. I'll just answer to all of you in one.

          @Pl45m4 The change makes no difference, the program still crashes in the same place. There are no issues on Windows for me either, only on Linux.

          @IgKh I know the stack trace makes no sense, that's why I'm writing on the forum. If I could've figured this out myself I wouldn't be here.
          I tried compiling without a PCH but the behaviour still stays the same. This is the modified code:

          #include "QtWidgets/qapplication.h"
          #include <iostream>
          
          static void use_qapp(QApplication* qApplication)
          {
            std::cout << qApp << '\n';
          }
          

          There's no change in the behaviour of the program.

          @Christian-Ehrlicher I'm building the application with CMake. RPATH is set to $ORIGIN and all the necessary Qt .so files copied to the same directory as the executable. Although debugging I set the LD_LIBRARY_PATH to the directory where Qt libraries were downloaded by the Qt Maintainance Tool, the behavoiur of the program was identical in both cases.
          I also tried debugging ld with LD_DEBUG=libs in case there was a problem with loading the wrong SO or loading the same SO twice but the outputs of both programs were identical up to the point where one crashed.

          I suspect the problems likely have something to do with putting the shared objects along with the executable, which is an unconventional approach on Linux, but I just can't figure out why that would be a problem.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #9

          @Jakob-Kenda
          I don't know where it would get you, but have you tried comparing the value of the qApp (QApplication::instance()) where you use it against the address of the QApplication qApplication in your main()? I presume they are supposed to be equal [they are for me], are they?

          Also, although it should not, does it differ if you use qApp back in main() or in some function which is not static?

          Finally per the stack trace it looks to me like it is happening inside the QApplication qApplication constructor rather than later on, e.g. during use_qapp(). Put some debug output statements in to make sure you really do come out of the constructor and proceed to later statements?

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #10

            Please start with QT_DEBUG_PLUGINS - it looks like the xcb plugin gets not loaded, only the offscreen one.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            2
            • J Jakob Kenda

              Thank you for your replies. I'll just answer to all of you in one.

              @Pl45m4 The change makes no difference, the program still crashes in the same place. There are no issues on Windows for me either, only on Linux.

              @IgKh I know the stack trace makes no sense, that's why I'm writing on the forum. If I could've figured this out myself I wouldn't be here.
              I tried compiling without a PCH but the behaviour still stays the same. This is the modified code:

              #include "QtWidgets/qapplication.h"
              #include <iostream>
              
              static void use_qapp(QApplication* qApplication)
              {
                std::cout << qApp << '\n';
              }
              

              There's no change in the behaviour of the program.

              @Christian-Ehrlicher I'm building the application with CMake. RPATH is set to $ORIGIN and all the necessary Qt .so files copied to the same directory as the executable. Although debugging I set the LD_LIBRARY_PATH to the directory where Qt libraries were downloaded by the Qt Maintainance Tool, the behavoiur of the program was identical in both cases.
              I also tried debugging ld with LD_DEBUG=libs in case there was a problem with loading the wrong SO or loading the same SO twice but the outputs of both programs were identical up to the point where one crashed.

              I suspect the problems likely have something to do with putting the shared objects along with the executable, which is an unconventional approach on Linux, but I just can't figure out why that would be a problem.

              I Online
              I Online
              IgKh
              wrote on last edited by
              #11

              @Jakob-Kenda said in Strange crash in QApplication constructor:

              I suspect the problems likely have something to do with putting the shared objects along with the executable, which is an unconventional approach on Linux, but I just can't figure out why that would be a problem.

              That is a good hint, you should have mentioned that the application is deployed, and not run from the build tree as is. This approach is not as unusual as you say, this is the principal that AppImage packages operate on. You can use Qt like this, but it is more involved than just copying shared libraries and adjusting RPATH. The issue is plugins, which require a particular directory structure, and in many cases a qt.conf file to ensure the right set of plugins is used. Mismatch is the source of many a bizarre issue, although it is unclear how exactly it happens in your case. The information from running the application with LD_DEBUG and QT_DEBUG_PLUGINS may help.

              You may also be interested in something like https://github.com/linuxdeploy/linuxdeploy-plugin-qt/ to automate correct deployment of Qt.

              J 1 Reply Last reply
              0
              • J Offline
                J Offline
                Jakob Kenda
                wrote on last edited by
                #12

                @Christian-Ehrlicher said in Strange crash in QApplication constructor:

                Please start with QT_DEBUG_PLUGINS - it looks like the xcb plugin gets not loaded, only the offscreen one.

                The xcb plugin was loaded - Here is the QT_DEBUG_PLUGINS output.

                Even if the plugin wasn't found, this wouldn't cause a crash where it did.

                1 Reply Last reply
                0
                • I IgKh

                  @Jakob-Kenda said in Strange crash in QApplication constructor:

                  I suspect the problems likely have something to do with putting the shared objects along with the executable, which is an unconventional approach on Linux, but I just can't figure out why that would be a problem.

                  That is a good hint, you should have mentioned that the application is deployed, and not run from the build tree as is. This approach is not as unusual as you say, this is the principal that AppImage packages operate on. You can use Qt like this, but it is more involved than just copying shared libraries and adjusting RPATH. The issue is plugins, which require a particular directory structure, and in many cases a qt.conf file to ensure the right set of plugins is used. Mismatch is the source of many a bizarre issue, although it is unclear how exactly it happens in your case. The information from running the application with LD_DEBUG and QT_DEBUG_PLUGINS may help.

                  You may also be interested in something like https://github.com/linuxdeploy/linuxdeploy-plugin-qt/ to automate correct deployment of Qt.

                  J Offline
                  J Offline
                  Jakob Kenda
                  wrote on last edited by
                  #13

                  @IgKh said in Strange crash in QApplication constructor:

                  The information from running the application with LD_DEBUG and QT_DEBUG_PLUGINS may help.

                  Here is the output of LD_DEBUG=libs, you may find something I missed despite looking at it for 2 days :)

                  I 1 Reply Last reply
                  0
                  • J Jakob Kenda

                    Hi,

                    I'm having a problem with the Qt application I'm developing.

                    I have 2 applications, one of them is crashing and the other one isn't. The crash occurs in QWindowSystemInterface::screenAdded because qGuiApp is null.

                    I've narrowed it down to QCoreApplication::self.storeRelaxed properly setting the global application in one application and having no effect in the other (QApplication::instance() and thus qApp stays null).

                    I tried to diagnose the problem with LD_DEBUG and it shows the libraries they are loading are exactly the same, in the same order and everything.

                    I don't know what else to do, can someone help me?

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #14

                    @Jakob-Kenda said in Strange crash in QApplication constructor:

                    I have 2 applications, one of them is crashing and the other one isn't.

                    Have you at least output const char *qVersion() (not QT_VERSION_STR) in both just to make sure?

                    1 Reply Last reply
                    0
                    • J Jakob Kenda

                      @IgKh said in Strange crash in QApplication constructor:

                      The information from running the application with LD_DEBUG and QT_DEBUG_PLUGINS may help.

                      Here is the output of LD_DEBUG=libs, you may find something I missed despite looking at it for 2 days :)

                      I Online
                      I Online
                      IgKh
                      wrote on last edited by
                      #15

                      @Jakob-Kenda Correct me if I'm wrong, but that looks like it was taken with the LD_LIBRARY_PATH set to the Qt installation?

                      J 1 Reply Last reply
                      0
                      • I IgKh

                        @Jakob-Kenda Correct me if I'm wrong, but that looks like it was taken with the LD_LIBRARY_PATH set to the Qt installation?

                        J Offline
                        J Offline
                        Jakob Kenda
                        wrote on last edited by
                        #16

                        @IgKh Yes, that was for debugging purposes. Doesn't matter, the outcome is the same.

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #17

                          Hi,

                          If I were you, I would check the code generated by the compiler.
                          I suspect some optimization might get applied or static initialization order is at play. Also note that qApp is a macro.
                          One thing you can do is try is using QApplication::instance() in place of qApp.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          J 1 Reply Last reply
                          0
                          • SGaistS SGaist

                            Hi,

                            If I were you, I would check the code generated by the compiler.
                            I suspect some optimization might get applied or static initialization order is at play. Also note that qApp is a macro.
                            One thing you can do is try is using QApplication::instance() in place of qApp.

                            J Offline
                            J Offline
                            Jakob Kenda
                            wrote on last edited by
                            #18

                            @SGaist I know it's a macro, I've already tried expanding it myself; the result was exactly the same.

                            I'll try to analyze the generated code, thanks.

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved