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. Get the instance of QApplication or QCoreApplication inside dll qt 4.8

Get the instance of QApplication or QCoreApplication inside dll qt 4.8

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 2.3k 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.
  • M Offline
    M Offline
    meganathan
    wrote on last edited by
    #1

    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

    jsulmJ 1 Reply Last reply
    0
    • M meganathan

      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

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

      @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
      1
      • M Offline
        M Offline
        meganathan
        wrote on last edited by
        #3

        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.

        jsulmJ 1 Reply Last reply
        0
        • M meganathan

          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.

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

          @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
          1
          • jsulmJ jsulm

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

            M Offline
            M Offline
            meganathan
            wrote on last edited by
            #5

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

            jsulmJ 1 Reply Last reply
            0
            • M meganathan

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

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

              @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
              2

              • Login

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