Results 1 to 6 of 6

Thread: MySQL Connection

  1. #1
    Join Date
    Dec 2012
    Posts
    13
    Thanks
    11
    Qt products
    Qt5
    Platforms
    Windows

    Question MySQL Connection

    Hey!

    I need make an MySql connection, but I receive this error:
    http://i.imgur.com/weMsU.png

    My code:
    Qt Code:
    1. #include <QtSql>
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. db->addDatabase( "QMYSQL3" ) ;
    2. db->setDatabaseName( "dbToConnectTo" ) ;
    3. db->setHostName( "localhost" ) ;
    4. db->setUserName( "dbUser" ) ;
    5. db->setPassword( "dbPassword" ) ;
    6. if ( !db->open() ) {
    7. QMessageBox *Ola = new QMessageBox(ui->centralWidget);
    8. Ola->setText("Failed opening database dbToConnectTo\nReason:\n\n" + db->lastError().driverText() + "\n\n" + db->lastError().databaseText());
    9. Ola->setIcon(QMessageBox::Warning);
    10. Ola->setStyleSheet("background: none");
    11. Ola->show();
    12. }
    To copy to clipboard, switch view to plain text mode 

    In .pro:
    Qt Code:
    1. QT += sql
    To copy to clipboard, switch view to plain text mode 

    Please help me :/
    hugs

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: MySQL Connection

    What does QSqlDatabase::drivers() say? You probably forget to distribute the right plugins alongside your application or haven't build the mysql plugin at all.

  3. The following user says thank you to Lykurg for this useful post:

    Niunzin (17th January 2013)

  4. #3
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MySQL Connection

    Or You don't have libraries from MySQL developer pack.

  5. The following user says thank you to Lesiok for this useful post:

    Niunzin (17th January 2013)

  6. #4
    Join Date
    Dec 2012
    Posts
    13
    Thanks
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: MySQL Connection

    Have only QSQLITE in drivers... where I can download mysql drivers?

  7. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: MySQL Connection

    You have to compile them yourself. In the documentation you'll find how...

  8. The following user says thank you to Lykurg for this useful post:

    Niunzin (17th January 2013)

  9. #6
    Join Date
    Dec 2012
    Posts
    13
    Thanks
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: MySQL Connection

    Quote Originally Posted by Lykurg View Post
    You have to compile them yourself. In the documentation you'll find how...
    Wow soo fast xD

    Thanks! ;D

Similar Threads

  1. Qt with mysql connection ???
    By sai_3289 in forum Qt Programming
    Replies: 3
    Last Post: 7th October 2012, 00:58
  2. Connection to MySQL
    By giriuvce in forum Qt Programming
    Replies: 12
    Last Post: 23rd January 2012, 02:59
  3. Regarding MYSQL connection
    By sudheer168 in forum Qt Programming
    Replies: 3
    Last Post: 16th October 2009, 15:34
  4. mysql 5 connection
    By GuL in forum Newbie
    Replies: 37
    Last Post: 18th August 2008, 15:11
  5. Mysql connection
    By yesraaj in forum Newbie
    Replies: 2
    Last Post: 23rd February 2007, 05: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.