PDA

View Full Version : Error connecting to MySQL



probine
23rd February 2006, 09:45
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"); ---- ?

probine
23rd February 2006, 09:53
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 ?

Everall
23rd February 2006, 10:01
in


db.setHostName = ("localhost");

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

Cheers

Everall
23rd February 2006, 10:06
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

probine
23rd February 2006, 10:45
I typed:

./configure -qt-sql-mysql

The shell said:

MySQL support cannot be enabled due to functionality tests!

What is wrong ?

jacek
23rd February 2006, 10:46
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).

probine
23rd February 2006, 10:51
MySQL is up and running.

What do you mean with libraries ? What libraries ?

jacek
23rd February 2006, 11:03
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.

probine
23rd February 2006, 11:30
I installed 2 rpms: "MySQL-server...rpm" and "MySQL-client...rpm", but I cannot find libmysqlclient.so

What am I missing to install ?

Everall
23rd February 2006, 11:41
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.

jacek
23rd February 2006, 11:42
What am I missing to install ?
Try mysql-libs and mysql-devel.

probine
23rd February 2006, 16:59
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 ?

jacek
23rd February 2006, 17:04
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?$ locate mysql.h
$ locate libmysqlclient

probine
23rd February 2006, 17:12
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

jacek
23rd February 2006, 17:14
Then you have to add:
-I /usr/include/mysql/ -L /usr/lib/mysql/to configure options.

probine
23rd February 2006, 21:58
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]#

jacek
23rd February 2006, 22:14
Try:$ cd $QTDIR/src
$ make sub-plugins

probine
23rd February 2006, 22:33
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 ?

jacek
23rd February 2006, 22:42
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.

probine
23rd February 2006, 23:11
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 ?

jacek
23rd February 2006, 23:13
All MySQL is installed, what are the commands to install Qt-4.1.x with MySQL ?
The ones from your eight post in this thread, but without sub-plugins.