Results 1 to 12 of 12

Thread: [QSqlQuery] Problem with not open database

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default [QSqlQuery] Problem with not open database

    Hi folks. I'm trying to write simple database program base on MySQL. I've established connection with database but I'can query. Here is what I'm talking about:
    Qt Code:
    1. #include "myquery.h"
    2.  
    3. MyQuery::MyQuery(QWidget *parent)
    4. : QMainWindow(parent)
    5. {
    6. db=QSqlDatabase::addDatabase("QMYSQL", "lge");
    7. db.setDatabaseName("WR");
    8. db.setHostName("localhost");
    9. db.setUserName("root");
    10. db.setPassword("password");
    11. using std::cout;
    12. if(db.open())
    13. {
    14. cout<<"Database opend.\n";
    15. }
    16.  
    17. cout<<query.exec("SELECT * FROM items");
    18. }
    To copy to clipboard, switch view to plain text mode 
    I'm trying to run this under WinXP. I've added "CONFIG+=console" to see std output and I'm getting:
    Database opend.
    QSqlQuery::exex:database not open
    0
    What I'm doing wrong?
    Last edited by xkazielx; 20th July 2009 at 14:17. Reason: updated contents

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
  •  
Qt is a trademark of The Qt Company.