Results 1 to 15 of 15

Thread: QSqlQuery problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlQuery problem

    Quote Originally Posted by MarkoSan View Post
    Thas means I am not connected to database??
    Not necessarily. What does QSqlQuery::lastError() return?

  2. The following user says thank you to jacek for this useful post:

    MarkoSan (14th January 2008)

  3. #2
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QSqlQuery problem

    God damn, the line
    Qt Code:
    1. qDebug() << query.lastError().text(); // debug
    To copy to clipboard, switch view to plain text mode 
    returns
    Qt Code:
    1. warning: "No database selected QMYSQL: Unable to execute query"
    To copy to clipboard, switch view to plain text mode 
    . Jacek, thanks for hints, but clear this up for me please. How is it possible that in the same object and in other method, one time the database is active and the second time, like in this problem, it goes offline. Is there any timeout setting for MySQL database???
    Qt 5.3 Opensource & Creator 3.1.2

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlQuery problem

    What happens in removeAllMerchandize()?

  5. #4
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QSqlQuery problem

    Here is code, nothing special:
    Qt Code:
    1. void CMerchandizeBrowser::removeAllMerchandize()
    2. {
    3. qDebug() << "Entered CMerchandizeBrowser::removeAllMerchandize ..."; // debug
    4. // qDebug() << "Number of pics: " << m_ImagesList.count();
    5. // for(qint16 iIndex=0; iIndex<m_ImagesList.count(); iIndex++)
    6. // {
    7. // m_ImagesList.removeAt(iIndex); // removes item
    8. // }
    9. //clear(); // clear slides of all images
    10. d->slideImages.clear(); // clears intertnal pic presentation
    11. //update(); // updates screen
    12. qDebug() << "Exiting CMerchandizeBrowser::removeAllMerchandize ..."; // debug
    13. }
    To copy to clipboard, switch view to plain text mode 

    And d is private class under CMerchandizeBrowser. Let me comment it and then see what happens.
    Qt 5.3 Opensource & Creator 3.1.2

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlQuery problem

    How do you connect to the database? Do you use a named connection?

  7. #6
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QSqlQuery problem

    I've coded database singleton class with your help, I think, a while ago and I am reusing it now in this application. Do you need a code?
    Qt 5.3 Opensource & Creator 3.1.2

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlQuery problem

    No, I just want to know the line with addDatabase().

  9. #8
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QSqlQuery problem

    Ok, here is the whole constructor of my CDatabaseFoundation class:
    Qt Code:
    1. CDatabaseFoundation::CDatabaseFoundation(QString db_type, QString db_host,
    2. QString db_name, QString db_username,
    3. QString db_password): QObject()
    4. {
    5. // sets up database paramaters
    6. m_Database=QSqlDatabase::addDatabase(db_type);
    7. m_Database.setHostName(db_host);
    8. m_Database.setUserName(db_username);
    9. m_Database.setPassword(db_password);
    10.  
    11. // tries to connect to database
    12. m_bConnectionEstablished=m_Database.open();
    13. if(!m_bConnectionEstablished)
    14. qFatal("Failed to connect to database. Aborting.");
    15. //create database + tables if they don't exists yet
    16. //CreateDatabaseAndTables();
    17.  
    18. //call seletedDatabase statement here because you're sure the the database exists
    19. m_Database.setDatabaseName(db_name);
    20.  
    21.  
    22. /*
    23.   m_pModel=new QSqlRelationalTableModel(this);
    24.   Q_CHECK_PTR(m_pModel);
    25.   //all changes will be cached in the model until either submitAll() or revertAll() is called
    26.   m_pModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
    27. */
    28. //addRelations(m_pModel);
    29.  
    30. }
    To copy to clipboard, switch view to plain text mode 
    Qt 5.3 Opensource & Creator 3.1.2

  10. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlQuery problem

    Quote Originally Posted by MarkoSan View Post
    // tries to connect to database
    m_bConnectionEstablished=m_Database.open();
    if(!m_bConnectionEstablished)
    qFatal("Failed to connect to database. Aborting.");
    //create database + tables if they don't exists yet
    //CreateDatabaseAndTables();

    //call seletedDatabase statement here because you're sure the the database exists
    m_Database.setDatabaseName(db_name);
    As the setDatabaseName() docs say: "This must be done before the connection is opened or it has no effect;". Put that line before the call to open().

  11. The following user says thank you to jacek for this useful post:

    MarkoSan (14th January 2008)

  12. #10
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QSqlQuery problem

    Ok, jacek, now query works fine. But please tell me, how is it possible that the SAME CODE worked before?????
    Qt 5.3 Opensource & Creator 3.1.2

  13. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlQuery problem

    Quote Originally Posted by MarkoSan View Post
    how is it possible that the SAME CODE worked before?????
    Yesterday was the 13th.

  14. #12
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QSqlQuery problem

    Hmm, you can mock at me as much as you want, but in the same object other method works without problem, I tried it now. I have to solve this mistery, anyway, jacek, thank you very very much for your guidance.
    Qt 5.3 Opensource & Creator 3.1.2

Similar Threads

  1. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35
  2. QSqlQuery problem
    By MarkoSan in forum Qt Programming
    Replies: 11
    Last Post: 18th December 2007, 13:25
  3. QSqlQuery error
    By skuda in forum Qt Programming
    Replies: 2
    Last Post: 2nd November 2007, 08:43
  4. [QMYSQL] connection problem
    By chaos_theory in forum Installation and Deployment
    Replies: 5
    Last Post: 2nd July 2007, 09:52
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.