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. how stop the "QPixmap: Must construct a QGuiApplication before a QPixmap" in a dll
Forum Updated to NodeBB v4.3 + New Features

how stop the "QPixmap: Must construct a QGuiApplication before a QPixmap" in a dll

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 3 Posters 3.7k 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.
  • K kenchan

    I am linking my own dll to a main application. That dll creates its own set icons. When it does this I get an error message saying "QPixmap: Must construct a QGuiApplication before a QPixmap" The dll is loaded after the main program creates a QApplication.

    How can I prevent this error?

    This error only happens in the release code.
    OS: Widows 10.
    Qt version: 5.15.2
    Compiler: Microsoft Visual Studio C++ compiler 16.11.31624.102 (x86_amd64)
    Any assistance will be gratefully received, thanks in advance.

    JKSHJ Offline
    JKSHJ Offline
    JKSH
    Moderators
    wrote on last edited by
    #2

    @kenchan said in how stop the "QPixmap: Must construct a QGuiApplication before a QPixmap" in a dll:

    The dll is loaded after the main program creates a QApplication.

    How do you guarantee this?

    That dll creates its own set icons.

    Does the DLL create the icons as soon as it is loaded? (e.g. because you have global static objects?) Ideally, the icons shouldn't be created until you call a function in the DLL.

    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

    K 1 Reply Last reply
    0
    • JKSHJ JKSH

      @kenchan said in how stop the "QPixmap: Must construct a QGuiApplication before a QPixmap" in a dll:

      The dll is loaded after the main program creates a QApplication.

      How do you guarantee this?

      That dll creates its own set icons.

      Does the DLL create the icons as soon as it is loaded? (e.g. because you have global static objects?) Ideally, the icons shouldn't be created until you call a function in the DLL.

      K Offline
      K Offline
      kenchan
      wrote on last edited by kenchan
      #3

      @JKSH Thanks for your reply.

      I load the dll myself after the Application is created in the main function of the parent app.

      The dll loads it's own icon buttons as soon as it loaded. This happens in a "start" function in the dll after it loads successfully.
      No global static objects used.

      JKSHJ 1 Reply Last reply
      0
      • K kenchan

        @JKSH Thanks for your reply.

        I load the dll myself after the Application is created in the main function of the parent app.

        The dll loads it's own icon buttons as soon as it loaded. This happens in a "start" function in the dll after it loads successfully.
        No global static objects used.

        JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #4

        You're welcome.

        @kenchan said in how stop the "QPixmap: Must construct a QGuiApplication before a QPixmap" in a dll:

        I load the dll myself after the Application is created in the main function of the parent app.

        The dll loads it's own icon buttons as soon as it loaded. This happens in a "start" function in the dll after it loads successfully.
        No global static objects used.

        Hmm... that's very interesting.

        Add some debugging calls in your code. What do you see? (Also pay attention to the order of messages: When does the QPixmap error appear, relative to these debug messages?):

        // main.cpp
        int main(int argc, char *argv[])
        {
            qDebug() << "Main application, before qApp:" << QCoreApplication::instance();
            QApplication app(argc, argv);
            qDebug() << "Main application, after qApp:" << QCoreApplication::instance();
        
            // ...
        }
        
        // DLL
        void start()
        {
            qDebug() << "DLL, before loading icons:" << QCoreApplication::instance();
        
            // ... Load icons here...
        
            qDebug() << "DLL, after loading icons:" << QCoreApplication::instance();    
        }
        

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        Christian EhrlicherC K 2 Replies Last reply
        0
        • JKSHJ JKSH

          You're welcome.

          @kenchan said in how stop the "QPixmap: Must construct a QGuiApplication before a QPixmap" in a dll:

          I load the dll myself after the Application is created in the main function of the parent app.

          The dll loads it's own icon buttons as soon as it loaded. This happens in a "start" function in the dll after it loads successfully.
          No global static objects used.

          Hmm... that's very interesting.

          Add some debugging calls in your code. What do you see? (Also pay attention to the order of messages: When does the QPixmap error appear, relative to these debug messages?):

          // main.cpp
          int main(int argc, char *argv[])
          {
              qDebug() << "Main application, before qApp:" << QCoreApplication::instance();
              QApplication app(argc, argv);
              qDebug() << "Main application, after qApp:" << QCoreApplication::instance();
          
              // ...
          }
          
          // DLL
          void start()
          {
              qDebug() << "DLL, before loading icons:" << QCoreApplication::instance();
          
              // ... Load icons here...
          
              qDebug() << "DLL, after loading icons:" << QCoreApplication::instance();    
          }
          
          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #5

          @JKSH said in how stop the "QPixmap: Must construct a QGuiApplication before a QPixmap" in a dll:

          I load the dll myself after the Application is created in the main function of the parent app.

          How do you do this?

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

          K 1 Reply Last reply
          0
          • JKSHJ JKSH

            You're welcome.

            @kenchan said in how stop the "QPixmap: Must construct a QGuiApplication before a QPixmap" in a dll:

            I load the dll myself after the Application is created in the main function of the parent app.

            The dll loads it's own icon buttons as soon as it loaded. This happens in a "start" function in the dll after it loads successfully.
            No global static objects used.

            Hmm... that's very interesting.

            Add some debugging calls in your code. What do you see? (Also pay attention to the order of messages: When does the QPixmap error appear, relative to these debug messages?):

            // main.cpp
            int main(int argc, char *argv[])
            {
                qDebug() << "Main application, before qApp:" << QCoreApplication::instance();
                QApplication app(argc, argv);
                qDebug() << "Main application, after qApp:" << QCoreApplication::instance();
            
                // ...
            }
            
            // DLL
            void start()
            {
                qDebug() << "DLL, before loading icons:" << QCoreApplication::instance();
            
                // ... Load icons here...
            
                qDebug() << "DLL, after loading icons:" << QCoreApplication::instance();    
            }
            
            K Offline
            K Offline
            kenchan
            wrote on last edited by
            #6

            @JKSH
            Ok I will do that and get back with the results.

            K 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              @JKSH said in how stop the "QPixmap: Must construct a QGuiApplication before a QPixmap" in a dll:

              I load the dll myself after the Application is created in the main function of the parent app.

              How do you do this?

              K Offline
              K Offline
              kenchan
              wrote on last edited by
              #7

              @Christian-Ehrlicher
              I use a QLibrary to load my dlls.

              Christian EhrlicherC 1 Reply Last reply
              0
              • K kenchan

                @Christian-Ehrlicher
                I use a QLibrary to load my dlls.

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #8

                @kenchan said in how stop the "QPixmap: Must construct a QGuiApplication before a QPixmap" in a dll:

                I use a QLibrary to load my dlls.

                I would deny this. Please use a dependency walker to see if it does not get loaded directly. Also use QT_FATAL_WARNINGS and/or a debugger to get the backtrace for the warning.

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

                K 1 Reply Last reply
                0
                • K kenchan

                  @JKSH
                  Ok I will do that and get back with the results.

                  K Offline
                  K Offline
                  kenchan
                  wrote on last edited by
                  #9

                  @kenchan
                  This the output from the inserted qDebug code.

                  Main application, before qApp: QObject(0x0)

                  ...

                  Main application, after qApp: RCApplication(0x59f1baab10)

                  ...

                  dll is loaded using QLibrary

                  ...

                  DLL, before loading icons: RCApplication(0x59f1baab10)

                  ...

                  DLL, after loading icons: RCApplication(0x59f1baab10)

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

                    And when comes the error message?
                    Also please use a debugger + QT_FATAL_WARNINGS as I suggest so you can see which code triggers the error message.

                    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
                    0
                    • Christian EhrlicherC Christian Ehrlicher

                      @kenchan said in how stop the "QPixmap: Must construct a QGuiApplication before a QPixmap" in a dll:

                      I use a QLibrary to load my dlls.

                      I would deny this. Please use a dependency walker to see if it does not get loaded directly. Also use QT_FATAL_WARNINGS and/or a debugger to get the backtrace for the warning.

                      K Offline
                      K Offline
                      kenchan
                      wrote on last edited by
                      #11

                      @Christian-Ehrlicher

                      It is true! These dlls are not known to the application at link time! so how can it know to load them until I want it to?

                      There are several of these dlls and the user can load and unload them using a dialog.
                      The application remembers which ones are to be loaded and loads them on each run, again using QLibrary.

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

                        Again: use a debugger and QT_FATAL_WARNINGS as described e.g. here to see which QPixmap triggers your error!

                        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
                        0
                        • laozeng1982L laozeng1982 referenced this topic on

                        • Login

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