Results 1 to 16 of 16

Thread: I want to use QMYSQL

  1. #1
    Join Date
    Jan 2009
    Posts
    78
    Thanks
    21
    Thanked 1 Time in 1 Post

    Default I want to use QMYSQL

    Hi.

    I tried a tipical:
    Qt Code:
    1. bool MainWindow::connecToDB(){
    2. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    3. db.setHostName("http://localhost");
    4. db.setDatabaseName("name");
    5. db.setUserName("user");
    6. db.setPassword("password");
    7. if(!db.open()){
    8. QMessageBox msgBox;
    9. msgBox.setModal(true);
    10. msgBox.setText("Error ...");
    11. msgBox.exec();
    12. return false;
    13. }
    14. return true;
    15. }
    To copy to clipboard, switch view to plain text mode 

    I came to the error:
    Qt Code:
    1. QSqlDatabase: QMYSQL driver not loaded
    2. QSqlDatabase: available drivers: QSQLITE QSQLITE2 QPSQL7 QPSQL
    To copy to clipboard, switch view to plain text mode 

    I suppose this has something to do with the license restrictions for driver included in Qt?

    I am using Debian/GNU LInux and i installed Qt with this Source Package: qt4-x11 (4.4.3-1).

    How do i install the driver?

    Thanks

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: I want to use QMYSQL

    you have to build mysql plugin or rebuild Qt with support of mysql.
    read this for more info.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    gt.beta2 (1st April 2009)

  4. #3
    Join Date
    Jan 2009
    Posts
    78
    Thanks
    21
    Thanked 1 Time in 1 Post

    Default Re: I want to use QMYSQL

    Thanks for the info ... but now i realise my system is in a big mess!
    I install something with apt, others with custom scrips (Qt Creator) and others by compiling the source code .... a big mess!
    I will delete everything and install it all from source starting by this.
    Wish me luck

  5. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: I want to use QMYSQL

    it's not to hard. but good luck
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  6. #5
    Join Date
    Jan 2009
    Posts
    78
    Thanks
    21
    Thanked 1 Time in 1 Post

    Default Re: I want to use QMYSQL

    Hello!

    Compiled Qt with:
    Qt Code:
    1. ./configure -qt-sql-mysql -dbus-linked -xshape
    2. make
    3. make install
    To copy to clipboard, switch view to plain text mode 

    Aparently it is working because i compiled some programs that i created before.

    About the initial issue, the MySql connection ...

    The initial example now gives me this message:
    Qt Code:
    1. mainwindow.h:5:24: error: QSqlDatabase: No such file or directory
    To copy to clipboard, switch view to plain text mode 

    Whant include files will i need?

    Thanks

  7. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: I want to use QMYSQL

    did you add
    CONFIG += sql
    line in your pro-file?
    did you include #include <QSqlDatabase> or #include <QtSql> in sources?
    last include, includes all sql module into your sources.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    gt.beta2 (3rd April 2009)

  9. #7
    Join Date
    Jan 2009
    Posts
    78
    Thanks
    21
    Thanked 1 Time in 1 Post

    Default Re: I want to use QMYSQL

    you were right about the
    Quote:
    CONFIG += sql
    I had #include <QtSqlDatabse> an now changed to QtSql but get the same:
    Qt Code:
    1. mainwindow.h:5:17: error: QtSql: No such file or directory
    To copy to clipboard, switch view to plain text mode 

    What am i missing here?!

  10. #8
    Join Date
    Jan 2009
    Posts
    78
    Thanks
    21
    Thanked 1 Time in 1 Post

    Default Re: I want to use QMYSQL

    got it ...
    QT += sql

  11. #9
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: I want to use QMYSQL

    oop, yes QT += sql, sorry for my mistake. just mistyped.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  12. #10
    Join Date
    Jan 2009
    Posts
    78
    Thanks
    21
    Thanked 1 Time in 1 Post

    Default Re: I want to use QMYSQL

    And now for the final question ... i hope.

    I installed a tipical LAMP for testing the connection:
    Qt Code:
    1. apt-get install apache2 mysql-server php5 phpmyadmin
    To copy to clipboard, switch view to plain text mode 

    When using http://localhost for the HostName i get:
    Qt Code:
    1. Unknown MySQL server host 'http://localhost' (1) QMYSQL: Unable to connect
    To copy to clipboard, switch view to plain text mode 

    Now what

  13. #11
    Join Date
    Feb 2009
    Location
    Venezuela
    Posts
    10
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: I want to use QMYSQL

    MySQL is running??

    $ sudo /etc/init.d/mysql start

  14. #12
    Join Date
    Jan 2009
    Posts
    78
    Thanks
    21
    Thanked 1 Time in 1 Post

    Default Re: I want to use QMYSQL

    I can access to phpmyadmin ... so i supose yes.

  15. #13
    Join Date
    Feb 2009
    Location
    Venezuela
    Posts
    10
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: I want to use QMYSQL

    Try with:

    Qt Code:
    1. db.setHostName("localhost");
    To copy to clipboard, switch view to plain text mode 

    Without "http://".

  16. The following user says thank you to JhonJames for this useful post:

    gt.beta2 (3rd April 2009)

  17. #14
    Join Date
    Jan 2009
    Posts
    78
    Thanks
    21
    Thanked 1 Time in 1 Post

    Default Re: I want to use QMYSQL

    uff ... you were right

    Thanks

  18. #15
    Join Date
    Sep 2008
    Location
    Portugal
    Posts
    171
    Thanks
    57
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: I want to use QMYSQL

    Hello!
    And if the database is in a server with ip 192.168.1.100?
    I tried:
    Qt Code:
    1. db.setHostName("192.168.1.100");
    To copy to clipboard, switch view to plain text mode 

    and it is not connecting.

    Why is that? Must i give the port address or something?!

    Thanks

  19. #16
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: I want to use QMYSQL

    try to set port. check you firewall.
    can you connect to this address using Qt's example which is located in QTDIR/demos/sqlbrowser?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. Help with QMYSQL driver for QT 4.4.0: driver not loaded
    By khikho in forum Installation and Deployment
    Replies: 4
    Last Post: 1st April 2011, 15:00
  2. The strange problem:"QSqlDatabase: QMYSQL driver not loaded"
    By osmanthus in forum Installation and Deployment
    Replies: 2
    Last Post: 22nd January 2009, 15:12
  3. Building QODBC and QMYSQL
    By mtrpoland in forum Installation and Deployment
    Replies: 2
    Last Post: 25th November 2007, 16:11
  4. QMYSQL driver
    By Fastman in forum Installation and Deployment
    Replies: 2
    Last Post: 26th October 2007, 08:14
  5. QMYSQL loading problem
    By ridgesoft in forum Qt Programming
    Replies: 7
    Last Post: 20th May 2007, 14:47

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.