PDA

View Full Version : how to reconnect CORRECTLY qmysql database?



yaseminyilmaz
31st December 2009, 12:20
Hi all,

I've installed qt-sdk-win-opensource-2009.05.exe and then wrote a simple program to test whether QMYSQL plugin was successfully built and connected. As of now there is no problem but I need mysql_ping functionality. How to try to reconnect correctly if isOpen function returns false?

I've attached a part of code. Before executing a query, I want to test connectivity and reconnect if it's broken. In order to accomplish this, must removeDatabase be firstly called? Without definition of another a QSqlDatabase instance, can existing qtafx_db variable be usable? I'll pleasure so much if you can clarify this matter.

Wish you all the best,

int main (int argc, char** argv)
{
QCoreApplication qtafx_app (argc, argv);
bool qStatus;
{
QSqlDatabase qtafx_db = QSqlDatabase::addDatabase ("QMYSQL");
qtafx_db.setHostName ("");
qtafx_db.setDatabaseName ("");
qtafx_db.setUserName ("");
qtafx_db.setPassword ("");

qStatus = qtafx_db.open();

....
// before executing a query, I want to test connectivity and reconnect if it's broken
....

qtafx_db.close ();
qtafx_db.removeDatabase ();
}
}