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. dynamic library based on static qt library?
Qt 6.11 is out! See what's new in the release blog

dynamic library based on static qt library?

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 3 Posters 4.7k Views
  • 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.
  • V Offline
    V Offline
    VVVDEL
    wrote on last edited by
    #1

    The gui application based on static Qt and a dynamic lib A, lib A also based on static Qt.

    When run the application there was an error message says:
    QEventLoop: Cannot be used without QApplication
    QCoreApplication::applicationDirPath: Please instantiate the QApplication object first

    How to fix this?

    Thanks.

    1 Reply Last reply
    0
    • Pradeep KumarP Offline
      Pradeep KumarP Offline
      Pradeep Kumar
      wrote on last edited by
      #2

      HI,

      For gui based app, use QGUIApplication or QApplication, in ur main file.

      Thanks,

      Pradeep Kumar
      Qt,QML Developer

      1 Reply Last reply
      3
      • V Offline
        V Offline
        VVVDEL
        wrote on last edited by VVVDEL
        #3

        I used QApplication in main file, but the error is caused by the dynamic lib. So does it meas that the Application and the dynamic lib can't share the QApplication instance? Thanks! @Pradeep-Kumar

        1 Reply Last reply
        0
        • Pradeep KumarP Offline
          Pradeep KumarP Offline
          Pradeep Kumar
          wrote on last edited by
          #4

          u mean to say while compiling ur lib program, u are getting this errors?.

          Thanks,

          Pradeep Kumar
          Qt,QML Developer

          V 1 Reply Last reply
          0
          • Pradeep KumarP Pradeep Kumar

            u mean to say while compiling ur lib program, u are getting this errors?.

            Thanks,

            V Offline
            V Offline
            VVVDEL
            wrote on last edited by
            #5

            @Pradeep-Kumar said in dynamic library based on static qt library?:

            u mean to say while compiling ur lib program, u are getting this errors?.

            Thanks,

            The error occurs when running the application.
            When debugging, the code stops in the dynamic library, the code is create QQmlEngine:
            QQmlEngine *s_engine = new QQmlEngine;

            1 Reply Last reply
            0
            • V Offline
              V Offline
              VVVDEL
              wrote on last edited by VVVDEL
              #6

              I try to print the value of qApp, in the dynamic lib, it is 0x0,In the main application it has value.
              Is this normal? Thanks! @Pradeep-Kumar

              jsulmJ 1 Reply Last reply
              0
              • V VVVDEL

                I try to print the value of qApp, in the dynamic lib, it is 0x0,In the main application it has value.
                Is this normal? Thanks! @Pradeep-Kumar

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @VVVDEL Looks like the code from your library is executed before QApplication instance was created. Do you have any static variables? Do you execute any code from the library before creating QApplication instance?

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                V 1 Reply Last reply
                2
                • jsulmJ jsulm

                  @VVVDEL Looks like the code from your library is executed before QApplication instance was created. Do you have any static variables? Do you execute any code from the library before creating QApplication instance?

                  V Offline
                  V Offline
                  VVVDEL
                  wrote on last edited by
                  #8

                  @jsulm Thanks, and here is the code
                  main.cpp

                  #include "mainwindow.h"
                  #include <QApplication>
                  #include <testlib.h>
                  
                  int main(int argc, char *argv[])
                  {
                      QApplication a(argc, argv);
                      MainWindow w;
                      w.show();
                      TestLib testlib;
                  
                      return a.exec();
                  }
                  
                  

                  TestLib.cpp

                  #include "testlib.h"
                  #include <QQmlEngine>
                  
                  
                  TestLib::TestLib()
                  {
                      QQmlEngine *engine = new QQmlEngine;
                  }
                  
                  
                  jsulmJ 1 Reply Last reply
                  0
                  • V VVVDEL

                    @jsulm Thanks, and here is the code
                    main.cpp

                    #include "mainwindow.h"
                    #include <QApplication>
                    #include <testlib.h>
                    
                    int main(int argc, char *argv[])
                    {
                        QApplication a(argc, argv);
                        MainWindow w;
                        w.show();
                        TestLib testlib;
                    
                        return a.exec();
                    }
                    
                    

                    TestLib.cpp

                    #include "testlib.h"
                    #include <QQmlEngine>
                    
                    
                    TestLib::TestLib()
                    {
                        QQmlEngine *engine = new QQmlEngine;
                    }
                    
                    
                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @VVVDEL Do you have any static variables in your static library?

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    V 1 Reply Last reply
                    1
                    • jsulmJ jsulm

                      @VVVDEL Do you have any static variables in your static library?

                      V Offline
                      V Offline
                      VVVDEL
                      wrote on last edited by
                      #10

                      @jsulm No, The above code is the whole code.

                      jsulmJ 1 Reply Last reply
                      0
                      • V VVVDEL

                        @jsulm No, The above code is the whole code.

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @VVVDEL How did you build the static lib (same compiler and Qt version?)?

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        V 1 Reply Last reply
                        1
                        • jsulmJ jsulm

                          @VVVDEL How did you build the static lib (same compiler and Qt version?)?

                          V Offline
                          V Offline
                          VVVDEL
                          wrote on last edited by
                          #12

                          @jsulm said in dynamic library based on static qt library?:

                          @VVVDEL How did you build the static lib (same compiler and Qt version?)?

                          The Qt version is 5.5.1,and was staticly build under os x 10.10.5

                          jsulmJ 1 Reply Last reply
                          1
                          • V VVVDEL

                            @jsulm said in dynamic library based on static qt library?:

                            @VVVDEL How did you build the static lib (same compiler and Qt version?)?

                            The Qt version is 5.5.1,and was staticly build under os x 10.10.5

                            jsulmJ Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            @VVVDEL One moment, I thought your lib was static, now I realized that it is shared lib. In this case your shared lib contains Qt stuff AND you app does! (because both used static Qt build)
                            You should not use static libs this way.
                            Why do you want to use a static Qt build but still use a shared library? It would be much easier to use shared Qt libs.

                            https://forum.qt.io/topic/113070/qt-code-of-conduct

                            V 1 Reply Last reply
                            0
                            • jsulmJ jsulm

                              @VVVDEL One moment, I thought your lib was static, now I realized that it is shared lib. In this case your shared lib contains Qt stuff AND you app does! (because both used static Qt build)
                              You should not use static libs this way.
                              Why do you want to use a static Qt build but still use a shared library? It would be much easier to use shared Qt libs.

                              V Offline
                              V Offline
                              VVVDEL
                              wrote on last edited by
                              #14

                              @jsulm The original project was based on static Qt libs. I need to develop some plugins based on the project. Now I know that I need to use dynamic Qt libs.
                              Thanks you very much.

                              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