|
|
Hi Developers,
I stuck in a problem with my implementation - I try to create some
database connections and
hold them in a LIST.
see the sample code below.
I found out that the db->setXXXX() not work correct
e.g. db->setDatabaseName("sampledb"); cout << db->databaseName() << endl;
show an empty string .. and for this reason I got no database connection
running.
Please tell me if I wrong here but I think more its a Bug :-/
Comments are really welcome!
Chris
#include <QCoreApplication>
#include <QtSql>
bool create_dbc()
{
QString conname = "dbcon" ;
QSqlDatabase* db = new QSqlDatabase::QSqlDatabase();
if ( !db->isDriverAvailable("QPSQL") ) {
printf ( "Error: Driver not available please update!\n" );
delete db;
return false;
}
db->addDatabase("QPSQL" , conname );
db->setHostName("localhost");
db->setPort(5432);
db->setDatabaseName("sampledb");
db->setUserName("sampleuser");
db->setPassword("geheim");
//db->setConnectOptions();
db->database(conname,true);
if ( db->isValid() ) {
delete db;
return true;
}
delete db;
return false;
}
int main ( int argc , char** argv )
{
QCoreApplication a(argc,argv);
if ( !create_dbc() ) {
printf("no no no \n");
}
else {
printf("yyeehh\n");
}
return a.exec();
}
--
To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/
|
|