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. Problems with QtSqlDatabase and threads
Forum Updated to NodeBB v4.3 + New Features

Problems with QtSqlDatabase and threads

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 684 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 15 Nov 2013, 16:12 last edited by
    #1

    Hi, i have an application that use threads and (if possible) a Sqlite database.
    the main is this one:

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

    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;

    }@

    in the executer thread start function i have this:

    @QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("testDB.db3");
    if(db.open())
    {
    qDebug()<<"Database opened";
    db.close();
    }
    else
    {
    qDebug()<<"Problem opening database "<<db.lastError().text();
    }@

    but driver load failed and it gives me those errors:

    @
    QCoreApplication::applicationDirPath: Please instantiate the QApplication object first
    SqlDatabase: QSQLITE driver not loaded
    QSqlDatabase: available drivers:
    QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins
    @

    i think is because i start the executer thread before calling a.exec()..
    How can i solve this?

    thanks,
    Riccardo

    1 Reply Last reply
    0

    1/1

    15 Nov 2013, 16:12

    • Login

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