Raccoon29
10th December 2009, 14:49
Hi everyone,
I'm here to provide you some fun :)
Take this code and paste it in a QPushButton::clicked() slot
mydb db1;
if(db1.open())
QMessageBox::information(this,"DEBUG info","Connected");
db1.close();
then paste this somewhere in the .h or .cpp as you prefer
class mydb{
private:
QVector<QSqlDatabase*> *handle;
public:
mydb(){ handle=new QVector<QSqlDatabase*>(); }
~mydb(){ delete handle; }
bool open()
{
QSqlDatabase handle=QSqlDatabase::addDatabase("QMYSQL","connName");
handle.setHostName("host");
handle.setDatabaseName("db");
handle.setUserName("username");
handle.setPassword("password");
handle.open();
this->handle->append(&handle);
return handle.isOpen();
}
void close()
{
QSqlDatabase *h=handle->at(0);
if(h->isValid())
qDebug() << "Valid";
if(h->isOpen())
qDebug() << "Open";
h->close();
handle->remove(0);
}
};
includes
#include <QtGui>
#include <QtSql>
// these are enhough, don't forget QT+=sql in file .pro
I'm compiling with mingw and running under Windows Xp SP3.
To me this code runs clearly in release and raises exception in debug.
Switching between modes with QtCreator causes it to change behavior.
I see nothing wrong in code... maybe you can notice something I'm missing.
Have fun :D
I'm here to provide you some fun :)
Take this code and paste it in a QPushButton::clicked() slot
mydb db1;
if(db1.open())
QMessageBox::information(this,"DEBUG info","Connected");
db1.close();
then paste this somewhere in the .h or .cpp as you prefer
class mydb{
private:
QVector<QSqlDatabase*> *handle;
public:
mydb(){ handle=new QVector<QSqlDatabase*>(); }
~mydb(){ delete handle; }
bool open()
{
QSqlDatabase handle=QSqlDatabase::addDatabase("QMYSQL","connName");
handle.setHostName("host");
handle.setDatabaseName("db");
handle.setUserName("username");
handle.setPassword("password");
handle.open();
this->handle->append(&handle);
return handle.isOpen();
}
void close()
{
QSqlDatabase *h=handle->at(0);
if(h->isValid())
qDebug() << "Valid";
if(h->isOpen())
qDebug() << "Open";
h->close();
handle->remove(0);
}
};
includes
#include <QtGui>
#include <QtSql>
// these are enhough, don't forget QT+=sql in file .pro
I'm compiling with mingw and running under Windows Xp SP3.
To me this code runs clearly in release and raises exception in debug.
Switching between modes with QtCreator causes it to change behavior.
I see nothing wrong in code... maybe you can notice something I'm missing.
Have fun :D