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"); ---- ?
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 ?
Re: Error connecting to MySQL
in
Quote:
db.setHostName = ("localhost");
eliminate the = like in :
db.setHostName("localhost");
Cheers
Re: Error connecting to MySQL
Quote:
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
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 ?
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).
Re: Error connecting to MySQL
MySQL is up and running.
What do you mean with libraries ? What libraries ?
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.
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 ?
Re: Error connecting to MySQL
Quote:
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.
Re: Error connecting to MySQL
Quote:
Originally Posted by probine
What am I missing to install ?
Try mysql-libs and mysql-devel.
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 ?
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?
Code:
$ locate mysql.h
$ locate libmysqlclient
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
Re: Error connecting to MySQL
Then you have to add:
Code:
-I /usr/include/mysql/ -L /usr/lib/mysql/
to configure options.
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]#
Re: Error connecting to MySQL
Try:
Code:
$ cd $QTDIR/src
$ make sub-plugins
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 ?
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.
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 ?