PDA

View Full Version : My Mysql 5 and Qt 4.2.2 Problem (Driver not loaded)



fengtian.we
8th February 2007, 09:01
OS: Linux-FC6
Mysql:mysql-standard-5.0.21
QT:Qt version 4.2.2
mysql plugin:/usr/lib64/qt4/plugins/sqldrivers/libqsqlmysql.so



GDataBaseConnecter code:

#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <QtGlobal>
#include <QtPlugin>

class GDataBaseConnecter
{
Q_IMPORT_PLUGIN(qsqlmysql)
private:
QSqlDatabase gdb;

public:
GDataBaseConnecter();
bool connectToDataBase();
bool disconnectToDataBase();
QString runSelect();
bool runInsert();
};

GDataBaseConnecter::GDataBaseConnecter()
{
printf("this is gzq start.\n");
gdb.addDatabase("QMYSQL");
gdb.setHostName("fengtianwe");
gdb.setDatabaseName("qtbase");
gdb.setUserName("root");
gdb.setPassword("root");
printf("this is gzq over.\n");
}

bool GDataBaseConnecter::connectToDataBase()
{
printf("this is connect start.\n");
if(gdb.open())
{
printf("Open OK.\n");
}
else
{
printf("Open Cut.\n");
printf("This is Error : %s\n",gdb.lastError().text().toLatin1().data());
}
printf("this is connect over.\n");
}

---------------------------------
main code:

#include <QApplication>
#include "GDataBaseConnecter.h"

int main( int argc, char ** argv )
{
QApplication app( argc, argv );
printf("App is start.\n");
GDataBaseConnecter gdbc;
gdbc.connectToDataBase();
//return app.exec();
return 0;
}
---------------------------------

when I called the GDataBaseConnecter::connectToDataBase(),then console output:

This is Error : Driver not loaded Driver not loaded


why ?? why ?? why ??

may i shoud use the mysql 4.x?

fengtian.we
8th February 2007, 09:32
and the "qDebug() << QSqlDatabase::drivers();" code will output:
("QSQLITE", "QMYSQL3", "QMYSQL", "QODBC3", "QODBC", "QPSQL7", "QPSQL")

and I programing uesd MonkeyStudio IDE

patrik08
8th February 2007, 10:45
OS: Linux-FC6
Mysql:mysql-standard-5.0.21
QT:Qt version 4.2.2
mysql plugin:/usr/lib64/qt4/plugins/sqldrivers/libqsqlmysql.so

GDataBaseConnecter::GDataBaseConnecter()
{
printf("this is gzq start.\n");
gdb.addDatabase("QMYSQL");
gdb.setHostName("fengtianwe");
gdb.setDatabaseName("qtbase");
gdb.setUserName("root");
gdb.setPassword("root");
printf("this is gzq over.\n");
}


gdb.setUserName("root");
gdb.setPassword("root");
gdb.open(); /* open here !!! */
printf("this is gzq over.\n");

if (gdb..isOpen()) { /* or !gdb..isOpen()*/

}


and put connection name to better debug!

QStringList QSqlDatabase::connectionNames () [static]

I connect on 2 db lan & web on same time to send update query on 2° server ....




/* typedef QMap<QString, QString> Appsetting; Appsetting OneVar; from xml config tagname/value */

qDebug() << "### use 2 connection lan & web " << usedb2;

db_0 = QSqlDatabase::addDatabase("QMYSQL",QString("LanConnection_%1").arg(connectnr)); /* QMYSQL */
db_0.setHostName(OneVar["dbhost1"]);
db_0.setDatabaseName(OneVar["dbbase1"]);
db_0.setUserName(OneVar["dbuser1"]);
db_0.setPassword(OneVar["dbpass1"]); /* OneVar["LIMITSQL"] */
db_0.open();

if (db_0.isOpen()) {
cnn1 = true;
tableslist_0 = db_0.tables();
counttable_0 = tableslist_0.size();
qDebug() << "### table count primo " << tableslist_0.size();
} else {
cnn1 = false;
QMessageBox::warning(this, tr( "Message from %1" ).arg(_PROGRAM_NAME_),
(tr("Unable to connect on server base %1")
.arg(OneVar["dbhost1"])));
return;
}
cnn2 = false;
if (usedb2) {
db_1 = QSqlDatabase::addDatabase("QMYSQL",QString("WebConnection_%1").arg(connectnr)); /* QMYSQL */
db_1.setHostName(OneVar["dbhost2"]);
db_1.setDatabaseName(OneVar["dbbase2"]);
db_1.setUserName(OneVar["dbuser2"]);
db_1.setPassword(OneVar["dbpass2"]); /* OneVar["LIMITSQL"] */
db_1.open();

if (db_1.isOpen()) {

tableslist_1 = db_1.tables();
//////////////////////////// qDebug() << "### table count secondo " << tableslist_1.size();
cnn2 = true;
} else {
QMessageBox::warning(this, tr( "Message from %1" ).arg(_PROGRAM_NAME_),
(tr("Unable to connect on server web %1")
.arg(OneVar["dbhost2"])));
return;
}
}

jacek
8th February 2007, 13:06
GDataBaseConnecter::GDataBaseConnecter()
{
printf("this is gzq start.\n");
gdb.addDatabase("QMYSQL");
gdb.setHostName("fengtianwe");
gdb.setDatabaseName("qtbase");
gdb.setUserName("root");
gdb.setPassword("root");
printf("this is gzq over.\n");
}
Try:
GDataBaseConnecter::GDataBaseConnecter()
{
printf("this is gzq start.\n");
gdb = QSqlDatabase::addDatabase("QMYSQL");
gdb.setHostName("fengtianwe");
gdb.setDatabaseName("qtbase");
gdb.setUserName("root");
gdb.setPassword("root");
printf("this is gzq over.\n");
}

fengtian.we
9th February 2007, 09:11
Oh God!! thanks my friend!!

I got it! :

I do :
gdb.addDatabase("QMYSQL");

but the return value not get. so no driver loaded :)

shoud be this:
gdb=QSqlDatabase::addDatabase("QMYSQL");

ok,I get connect to mysql!!!!