Qt Forum

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

    Unsolved Get the instance of QApplication or QCoreApplication inside dll qt 4.8

    General and Desktop
    2
    6
    1291
    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.
    • M
      meganathan last edited by

      I have my QApplication created inside main() in QthreadTest project. From this project i have called the function inside library felix2.lib which is dynamically build.

      Inside felix2 , i need to have QApplication or QCoreApplication to connect to ODBC drivers. i tried using
      QCoreApplication *app1 = QApplication::instance(); which is returning NULL.

      QthreadTest:

      main.cpp:
      int main(int argc, char *argv[])
      {
      int i =0;
      QApplication a(argc, argv);
      QthreadTest w;
      w.show();
      return a.exec();
      }

      Qthreadtest.cpp
      void QthreadTest::startProgress()
      {
      analyze("Prompted");// function inside lib
      }

      Please help me with how to get the instance of Qapplication that is already defined in main.cpp inside the lib

      jsulm 1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @meganathan last edited by

        @meganathan https://doc.qt.io/qt-5/qapplication.html#qApp is your friend

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

        1 Reply Last reply Reply Quote 1
        • M
          meganathan last edited by

          i tried like this
          QCoreApplication *app1 = qApp->instance(); inside the library but the app1 is NULL , is there any other methods to get the instance.

          jsulm 1 Reply Last reply Reply Quote 0
          • jsulm
            jsulm Lifetime Qt Champion @meganathan last edited by

            @meganathan Why do you call instance on it?
            If you read documentation you will notice that qApp already gives you pointer to QApplication instance.

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

            M 1 Reply Last reply Reply Quote 1
            • M
              meganathan @jsulm last edited by

              @jsulm i used that to confirm whether qApp holds any instance or not.

              jsulm 1 Reply Last reply Reply Quote 0
              • jsulm
                jsulm Lifetime Qt Champion @meganathan last edited by

                @meganathan From documentation:
                "A global pointer referring to the unique application object"
                https://doc.qt.io/qt-5/qapplication.html#qApp

                qApp is the pointer to the instance.

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

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