[Qt-interest] how to reconnect CORRECTLY qmysql database?

Yasemin YILMAZ yaseyilmaz at gmail.com
Mon Jan 4 09:49:47 CET 2010


Hi all,



I've installed qt-sdk-win-opensource-2009.05.exe with LPGL licence 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? Does isOpen return false when the connection is lost really, doesn't
it?



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 qt_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 qt_app (argc, argv);

        bool qStatus;

        {

                        QSqlDatabase qt_db = QSqlDatabase::addDatabase
("QMYSQL");

                        qt_db.setHostName ("");

                        qt_db.setDatabaseName ("");

                        qt_db.setUserName ("");

                        qt_db.setPassword ("");



                        qStatus = qt_db.open();



                ....

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

                ....



                        qt_db.close ();

                        qt_db.removeDatabase ();

        }

        return qt_app.exec ();

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100104/348e9baf/attachment.html 


More information about the Qt-interest-old mailing list