Important: Please read the Qt Code of Conduct -

Please instantiate the QApplication object first

  • 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;

    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;





    int returnValue=a.exec();


    return returnValue;


    What is my fault?

  • Moderators

    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.

  • 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?

  • Moderators

    Usually, the opposite is true ;)

  • 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

Log in to reply