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. Please instantiate the QApplication object first

Please instantiate the QApplication object first

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 9.0k Views 1 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.
  • R Offline
    R Offline
    rileo8
    wrote on last edited by
    #1

    Hi,

    i.m trying to use QSqlDatabase to access a SQLITE database but it gives me that error while trying to load the plugin:

    Please instantiate the QApplication object first

    This it the main:

    @int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;
    w.showMaximized();

    QApplication::addLibraryPath("\Program Files\Diagnostico\plugins\sqldrivers\");

    QMutex *configurationMutex=new QMutex();
    Configuration *configuration=new Configuration();

    Checker checker(0,configuration,configurationMutex);
    Networker networker(0,configuration,configurationMutex);
    Executer executer(0,configuration,configurationMutex);

    QThread checkerThread;
    QThread networkerThread;
    QThread executerThread;

    QObject::connect(&executerThread,SIGNAL(started()),&executer,SLOT(Start()));
    QObject::connect(&w,SIGNAL(SignalTest()),&checker,SLOT(TestSlot()));

    checker.moveToThread(&checkerThread);
    networker.moveToThread(&networkerThread);
    executer.moveToThread(&executerThread);

    file_name();

    checkerThread.start();
    networkerThread.start();
    executerThread.start();

    int returnValue=a.exec();

    executerThread.wait();

    return returnValue;

    }@

    What is my fault?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      There are several. First, use this to add lib paths:
      @
      a.addLibraryPath("\Program Files\Diagnostico\plugins\sqldrivers\");
      @

      Then, you are have completely missed the exec() call (a.exec()); Without the event loop (which is started in exec()), signals and slots won't work, the GUI will not work, etc. You need to do all this at a later stage, once the event loop is running. Try redesigning a bit, and ask again if you have troubles. It will be easier to address problems one by one, as they appear.

      (Z(:^

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rileo8
        wrote on last edited by
        #3

        Hi ,

        i found that in release mode it works (same code i posted before) while in debug mode it doesn't....

        Maybe a debug mode issue?

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Usually, the opposite is true ;)

          (Z(:^

          1 Reply Last reply
          0
          • M Offline
            M Offline
            melongex
            wrote on last edited by
            #5

            I just had the same problem: Turns out I linked Qt5Widgets.lib instead of Qt5Widgetsd.lib

            The answer is a bit late, but it might help somebody else

            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