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. QPSQL Multithread Crash
Forum Updated to NodeBB v4.3 + New Features

QPSQL Multithread Crash

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.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.
  • Z Offline
    Z Offline
    zweistein
    wrote on last edited by
    #1

    Hello,

    Whats wrong with running this code in a thread:

    @ QSqlDatabase db = QSqlDatabase::addDatabase( "QPSQL", QString::number( (long long)(QThread::currentThread())) );
    db.setHostName( QString::fromStdString( m_Hostname ) );
    db.setPort( m_Port );
    db.setDatabaseName(QString::fromStdString( m_DatabaseName ));
    db.setUserName(QString::fromStdString( m_User ));
    db.setPassword(QString::fromStdString( m_PW ));

    bool online = db.open();
    if(!online) {
    //db.close();
    m_HasError = true;
    return DATA_CANCELLED;
    };

    QSqlQuery query(QString::fromStdString( m_CountMeltingsQuery ), db);@

    I mwan this runs, but when i close the MainWindow... The program crashes at:

    qsqlpsqld4.dll!QPSQLDriver::close() Zeile 848 C++ <--- Crash!
    QtSqld4.dll!QSqlDatabase::close() Zeile 882 C++
    ->

    The code in qpsqldriver is:
    @ if (d->connection)
    PQfinish(d->connection);
    d->connection = 0;@

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      Did you read "Threads and the SQL Module":http://qt-project.org/doc/qt-4.8/threads-modules.html#threads-and-the-sql-module of the QSqlDatabase documentation?

      Did you open another connection in another thread?
      Are you sure the code is running in the new thread?

      http://www.catb.org/~esr/faqs/smart-questions.html

      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