Results 1 to 1 of 1

Thread: QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins!

  1. #1
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Red face Re: QSqlDatabase: an instance of QCoreApplication is required for loading driver plug

    Hi,

    I having the said problem in a command line application, however I'm getting the error in Windows (mingw) and not in Linux.

    The code in the main is:
    Qt Code:
    1. #include <QObject>
    2. #include "mydbconn.h"
    3. #include <QSqlDatabase>
    4. #include <QSqlQuery>
    5. #include <QSqlError>
    6. #include <QDir>
    7. #include <QTextStream>
    8. #include <tclap/CmdLine.h>
    9. #include <QtCore/QCoreApplication>
    10.  
    11. int main(int argc, char *argv[])
    12. {
    13. QCoreApplication a(argc, argv);
    14. ...
    15.  
    16. mydb = QSqlDatabase::addDatabase("QMYSQL","connection1");
    17. mydb.setHostName(host);
    18. mydb.setPort(port.toInt());
    19. if (!userName.isEmpty())
    20. mydb.setUserName(userName);
    21. if (!password.isEmpty())
    22. mydb.setPassword(password);
    23.  
    24.  
    25.  
    26. mydb.setDatabaseName(dbName);
    27.  
    28. mydb.open();
    29.  
    30. // a.exec() Not execute the event loop. All the processes are in the main
    31. }
    To copy to clipboard, switch view to plain text mode 

    Any idea how to fix the problem?

    Thanks,
    Carlos.


    Added after 1 7 minutes:


    Ups... it gets fixed with

    #include <QtCore/QCoreApplication>
    QCoreApplication a(argc, argv);


    I was running another application that did not have those lines... All works fine now
    Last edited by qlands; 4th May 2012 at 13:18.

Similar Threads

  1. Replies: 1
    Last Post: 16th June 2011, 19:13
  2. Need Help:QSqlDatabase: QMYSQL driver not loaded
    By i4ba1 in forum Qt Programming
    Replies: 1
    Last Post: 9th January 2011, 18:39
  3. QSqlDatabase: QMYSQL driver not loaded
    By lise in forum Newbie
    Replies: 3
    Last Post: 1st June 2010, 13:09
  4. QSqlDatabase driver problem
    By croscato in forum Qt Programming
    Replies: 2
    Last Post: 21st November 2008, 16:16
  5. QCoreApplication And QSqlDatabase
    By ball in forum Qt Programming
    Replies: 1
    Last Post: 24th May 2006, 07:58

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.