PDA

View Full Version : Problems compiling a QT application for connecting with a remote mysql database



gorka_sm
15th April 2010, 15:15
Hello I am working with the Qt code of mythv-0.22 source code in a MythUbuntu distro in Ubuntu 9.10.
I am trying to modify the Qt code of mythv-022 for connecting to a remote database and obatining some data. I have used the Qt Developer and tried to modify the main.cpp class.
I make the following changes :

The main.h file has not been modified. I include the following .h files in the main.cpp project:

#include "qapplication.h"
#include "qsqldatabase.h"
#include "qsqlerror.h"
#include "qlabel.h"

In main.cpp I have writen the following code , which is supposed to be used for connecting to the Mysql Database:

void conection_server(void){
QSqlDatabase * conexion = QSqlDatabase::addDatabase("QMYSQL3");
conexion->setDatabaseName("mysql");
conexion->setUserName("root");
conexion->sethostName("152.168.54.5");
}

I compile and obtain the following mistake

"main.cpp:1107: error: cannot convert ´QSqlDatabase´ to ´QSqlDatabase´ in initialization"

The line 1107 is the following :

QSqlDatabase * conexion = QSqlDatabase::addDatabase("QMYSQL3");

Does anybody know how to solve this compilation mistake ?


Thanks ,Gorka

foxyproxy
15th April 2010, 15:59
QSqlDatabase::addDatabase ( const QString & type, const QString & connectionName = QLatin1String( defaultConnection ) ) doesn't return a pointer to QSqlDatabase.

borisbn
15th April 2010, 15:59
QSqlDatabase::addDatabase return object of class QSqlDatabase, but not pointer to it
do this:


QSqlDatabase connection = QSqlDatabase::addDatabase( ...


by the way, you shouldn't declare QSqlDatabase connection inside your function void conection_server(void), because it will destroyed when function will return.