Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: Error connecting to MySQL

  1. #1
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Error connecting to MySQL

    Using Qt-4.1.0 and MySQL 5.0.18

    After trying to compile this code:

    #include <QApplication>
    #include <QtSql>
    #include <iostream>
    using namespace std;

    int main(int argc, char * argv[])
    {
    cout << "Testing Qt and the connection to the database\n";
    QSqlDatabase db = QSqlDatabase::addDatabase("QMySQL");
    db.setHostName = ("localhost");
    return 1;
    }


    I get this error:

    s/linux-g++ -I. -I../../../include/QtCore -I../../../include/QtGui -I../../../include/QtSql -I../../../include -I. -I. -I. -o qtDatabase.o qtDatabase.cpp
    qtDatabase.cpp: In function ‘int main(int, char**)’:
    qtDatabase.cpp:11: error: invalid use of member (did you forget the ‘&’ ?)
    qtDatabase.cpp: At global scope:
    qtDatabase.cpp:6: warning: unused parameter ‘argc’
    qtDatabase.cpp:6: warning: unused parameter ‘argv’
    make: *** [qtDatabase.o] Error 1


    What is wrong with ---- db.setHostName = ("localhost"); ---- ?

  2. #2
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Error connecting to MySQL

    For some reason it did not work, but I copy and pasted the code from the website and now it compiled.

    The problem now is:

    QSqlDatabase: QMYSQL driver not loaded


    How do I load it ?

  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    99
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Error connecting to MySQL

    in
    db.setHostName = ("localhost");
    eliminate the = like in :
    db.setHostName("localhost");

    Cheers

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    99
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Error connecting to MySQL

    QSqlDatabase: QMYSQL driver not loaded
    How do I load it ?
    ///check database driver with :
    if (!QSqlDatabase::drivers().contains("QMYSQL"))
    QMessageBox::critical(this, "Unable to load database", "Needs the QMYSQL driver");

    If you get this error message, you probably didn't install the QMYSQL driver.
    To install it have a look at the Qt Centre FAQ : Enabling MySQL support

    Cheers

  5. #5
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Error connecting to MySQL

    I typed:

    ./configure -qt-sql-mysql

    The shell said:

    MySQL support cannot be enabled due to functionality tests!

    What is wrong ?

  6. #6
    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: Error connecting to MySQL

    Quote Originally Posted by probine
    MySQL support cannot be enabled due to functionality tests!

    What is wrong ?
    You don't have MySQL libraries or you didn't tell Qt where to find them (through -L and -I options).

  7. #7
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Error connecting to MySQL

    MySQL is up and running.

    What do you mean with libraries ? What libraries ?

  8. #8
    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: Error connecting to MySQL

    Quote Originally Posted by probine
    What do you mean with libraries ? What libraries ?
    The MySQL client libraries, that allow you to connect to MySQL server. Look for libmysqlclient.so file on your system and make sure you have the headers too.

  9. #9
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Error connecting to MySQL

    I installed 2 rpms: "MySQL-server...rpm" and "MySQL-client...rpm", but I cannot find libmysqlclient.so

    What am I missing to install ?

  10. #10
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    99
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Error connecting to MySQL

    I installed 2 rpms: "MySQL-server...rpm" and "MySQL-client...rpm", but I cannot find libmysqlclient.so

    What am I missing to install ?
    libqt4-mysql.rpm or something like that?
    Have a search in your packages.
    Last edited by Everall; 23rd February 2006 at 11:48.

  11. #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: Error connecting to MySQL

    Quote Originally Posted by probine
    What am I missing to install ?
    Try mysql-libs and mysql-devel.

  12. #12
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Error connecting to MySQL

    This are my packages I haves installed:

    [root@dhcp-57106 ~]# rpm -qa | grep mysql
    php-mysql-5.0.4-10
    mysqlclient10-3.23.58-6
    mysql-4.1.11-2
    mod_auth_mysql-2.6.1-4
    libdbi-dbd-mysql-0.7.1-3
    mysql-devel-4.1.11-2
    mysql-server-4.1.11-2
    mysql-bench-4.1.11-2

    I have been trying to find the mysql-libs for FC4, but I cannot...

    Do I need something else ? Where can I find the mysql-libs for FC4 ?

  13. #13
    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: Error connecting to MySQL

    Quote Originally Posted by probine
    Do I need something else ? Where can I find the mysql-libs for FC4 ?
    It's probably a part of other packages. If you have mysql-devel, then it should be already installed.

    What does this output?
    sh Code:
    1. $ locate mysql.h
    2. $ locate libmysqlclient
    To copy to clipboard, switch view to plain text mode 

  14. #14
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Error connecting to MySQL

    This is the output of both:

    [root@dhcp-57106 Qt-4.1.0]# locate mysql.h
    /usr/share/apps/quanta/doc/php/ref.mysql.html
    /usr/include/mysql/mysql.h
    /usr/local/Trolltech/Qt-4.1.0/src/sql/drivers/mysql/qsql_mysql.h
    /usr/local/Trolltech/Qt-4.1.0/include/Qt/qsql_mysql.h
    /usr/local/Trolltech/Qt-4.1.0/include/QtSql/qsql_mysql.h
    /home/santiago/programs/qt/src/sql/drivers/mysql/qsql_mysql.h
    /home/santiago/programs/qt/include/Qt/qsql_mysql.h
    /home/santiago/programs/qt/include/QtSql/qsql_mysql.h

    [root@dhcp-57106 Qt-4.1.0]# locate libmysqlclient
    /usr/lib/mysql/libmysqlclient_r.so.10.0.0
    /usr/lib/mysql/libmysqlclient_r.so
    /usr/lib/mysql/libmysqlclient.a
    /usr/lib/mysql/libmysqlclient.so.10.0.0
    /usr/lib/mysql/libmysqlclient.so.14
    /usr/lib/mysql/libmysqlclient_r.so.14.0.0
    /usr/lib/mysql/libmysqlclient.so.10
    /usr/lib/mysql/libmysqlclient_r.so.14
    /usr/lib/mysql/libmysqlclient.so.14.0.0
    /usr/lib/mysql/libmysqlclient_r.a
    /usr/lib/mysql/libmysqlclient.so
    /usr/lib/mysql/libmysqlclient_r.so.10

  15. #15
    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: Error connecting to MySQL

    Then you have to add:
    Qt Code:
    1. -I /usr/include/mysql/ -L /usr/lib/mysql/
    To copy to clipboard, switch view to plain text mode 
    to configure options.

  16. #16
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Error connecting to MySQL

    After configuring everything with the qt plugin as:

    ./configure -plugin-sql-mysql -I /usr/include/mysql/ -L /usr/lib/mysql/

    Everything went fine, but according to the documentation I should then type:

    make sub-plugins

    But, I get this error:

    [root@dhcp-57106 qt]# make sub-plugins
    make: *** No rule to make target `sub-plugins'. Stop.
    [root@dhcp-57106 qt]#

  17. #17
    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: Error connecting to MySQL

    Try:
    sh Code:
    1. $ cd $QTDIR/src
    2. $ make sub-plugins
    To copy to clipboard, switch view to plain text mode 

  18. #18
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to install Qt-4.1.0 and MySQL-4.x

    I am using Fedora Core 4.

    I would like to install Qt-4 and MySQL-4. I have downloaded and installed MySQL client and server with the libraries.

    I am going to install Qt from source... so please tell me what are the steps to have it installed and working with MySQL ?

  19. #19
    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: How to install Qt-4.1.0 and MySQL-4.x

    Quote Originally Posted by probine
    I am using Fedora Core 4.

    I would like to install Qt-4 and MySQL-4. I have downloaded and installed MySQL client and server with the libraries.

    I am going to install Qt from source... so please tell me what are the steps to have it installed and working with MySQL ?
    Please, don't start more than one thread on the same problem.

  20. #20
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Error connecting to MySQL

    ok... fresh start

    I am building Qt-4.1.x from source

    I would like to install Qt-4.1.x and MySQL-4.x.

    All MySQL is installed, what are the commands to install Qt-4.1.x with MySQL ?

Similar Threads

  1. How to use static mysql plugin
    By khikho in forum Qt Programming
    Replies: 7
    Last Post: 19th January 2009, 21:44
  2. mysql configuration with qt
    By bala in forum Installation and Deployment
    Replies: 3
    Last Post: 6th November 2007, 11:02
  3. qt4.3.1 mysql problem
    By twells55555 in forum Qt Programming
    Replies: 5
    Last Post: 8th October 2007, 21:26
  4. MySQL starting problem
    By shamik in forum General Discussion
    Replies: 5
    Last Post: 25th April 2007, 07:20
  5. Qt 4.1.4 & Mysql 5 on Linux x64
    By bothapn in forum Installation and Deployment
    Replies: 7
    Last Post: 4th August 2006, 13:23

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.