PDA

View Full Version : QSqlDatabase close method error in DEBUG mode



dan.niele
6th June 2012, 16:51
Hello to everyone.

I'm stuck on an error from QSqlDatabase.

I'm modifying a project wrote by other developers.

Last working configuration was VC6 with QT4 library and everything worked, but when I try to port it to Qt creator using QT4 library i got an "unknown error" message from QT.

The error occurs when I try to call QSqlDatabase close method:




DB_MSAccess::DB_getProductInfo()
{
openclose = m_RegisterDB.open(); // openclose return true, so the database is open
m_RegisterDB.close();
}


The QSqlDatabase is initialized in the constructor class and is declared private into header file.

DB_MSAccess::DB_MSAccess()

{
m_RegisterDB= QSqlDatabase::addDatabase("QODBC",MAIN_DB);
m_RegisterDB.setDatabaseName (MAIN_DB);
}


I forget to mention that the error occurs only in DEBUG -step by step mode. If I run the code either in RELEASE or DEBUG the code works perfectly.

Anyone knows how to help me??

Thanks for your help

amleto
6th June 2012, 17:32
You might like to point people to some discussion that you have already started on this. Just so you don't waste time re-hashing old ground.


http://www.qtforum.org/article/38055/qsqldatabase-close-method-error-in-debug-mode.html

dan.niele
6th June 2012, 18:02
Hi amleto,
thanks for your reply.


You might like to point people to some discussion that you have already started on this. Just so you don't waste time re-hashing old ground.


http://www.qtforum.org/article/38055...ebug-mode.html


Maybe you are right and I should have report the link to the other post.


Please tell me what do you mean about complete code. Below there are the two main class related to this error.

This is the DB_MSAccess class that inherits from DB_Interface:

class DB_MSAccess: public DB_Interface
{
public:

DB_MSAccess();
~DB_MSAccess();

quint16 getProdList(QString Id, QStringList* prodList);


protected:


private:
QSqlDatabase m_RegisterDB;

}
and the DB_Interface class is reported below (It contains only one virtual method):


class DB_Interface
{
public:
DB_Interface();

virtual quint16 getProdList(QString Id, QStringList* prodList);
}

I use the Qt Creator 2.3.0 and Qt 4.7.4 library.

Hope this can help you to help me :)

ChrisW67
7th June 2012, 03:34
There are no obvious errors in the code you have given us. I gather from the other thread that the error message is actually a Qt Creator error dialog (I cannot see the screen shot) and not output from this program. The observation that you do not get the message at all if you just run the program rather than running it in a debugger points at an issue with debugging not the program.. So, the issue looks like an interaction between your debugger and Qt Creator.

Try running the program in your debugger outside of Qt Creator. Any odd error messages from the debugger?
Which debugger? Which compiler?

dan.niele
8th June 2012, 10:32
Hi ChrisW67,
I use Qt Debugger vers. 2.3.0. The compiler is MinGW 4.4.0.

Try running the program in your debugger outside of Qt Creator. Any odd error messages from the debugger?
Which debugger? Which compiler?

What do you mean by "running the program outside Qt creator"? I don't know how do it. Could you explain me how do it please?

Thanks

wysota
9th June 2012, 14:07
Open command line, run gdb passing it the path to your executable, then type "run" and see what happens. If you want to step through the program this way then I suggest you read some tutorial on using gdb.