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. Reusing a QsqlQuery object too many times causes an unhandled exception SOLVED
Forum Updated to NodeBB v4.3 + New Features

Reusing a QsqlQuery object too many times causes an unhandled exception SOLVED

Scheduled Pinned Locked Moved General and Desktop
3 Posts 1 Posters 4.1k 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.
  • A Offline
    A Offline
    arnie
    wrote on 19 May 2011, 20:43 last edited by
    #1

    I have a very simple Qt based application (4.6.3) running on a Window7 system that is connecting to an MSSQL database running on a separate server. I can successfully make a connection to the DB and perform queries successfully.
    However, if i attempt to reuse the same QSqlQuery object a number of time, the query.exec() generates an Unhandled exception. In the code snippet below, the 3rd query fails. I have simplified the code sample for this post. I have tried to do a query.finish() after each query has been processed with no success. I then tried to use query.clear(), but that would also ALWAYS throw an unhandled exception. no matter when it is executed.
    The code was built and tested via Visual Studio.

    If I use a new QSqlQuery option for each query, the queries succeed.
    Am I doing something incorrectly?
    Thank You,

    Arnie

    @
    int main( int argc, char *argv[])
    {
    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    db.setHostName("myhostname");
    db.setDatabaseName("mydsn");
    db.setUserName("myuserid");
    db.setPassword("mypassword");
    bool ok = db.open();
    QSqlQuery query;

    query.exec("Select id from myTable");
    while (query.next())
    {
    int id = query.value(0).toInt();
    qDebug() << id;
    }

    query.exec("Select id from myTable");
    while (query.next())
    {
    int id = query.value(0).toInt();
    qDebug() << id;
    }

    query.exec("Select id from myTable"); //<--THIS query.exec never gets executed. The exception happens
    //here
    while (query.next())
    {
    int id = query.value(0).toInt();
    qDebug() << id;
    }
    ......
    @

    1 Reply Last reply
    0
    • A Offline
      A Offline
      arnie
      wrote on 19 May 2011, 20:45 last edited by
      #2

      My previous post should have said that the query.clear() ALWAYS throws an exception whenever it is executed. Sorry about that mistake.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        arnie
        wrote on 20 May 2011, 13:24 last edited by
        #3

        I have solved this problem. It turns out that while I was linking in the wrong versions of the Qt dlls. I was in some cases linking in the the debug version in the release build or the release version in the debug build. Once I figured this all of the unhandled exceptions were resolved.

        1 Reply Last reply
        0

        1/3

        19 May 2011, 20:43

        • Login

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