hey,
in my case it could be, that the network-connection is up (before the exec()) and during the exec() it could be down - so it blocks my application.
Before the exec() i watched with a thread if the network-connection is down - but during the exec() i don`t have any chance.
so what can i do?
Added after 24 minutes:
I`ve tried to build a QThread with my .exec():
Implementation in my QThread-Classe:
void cExecThread::run()
{
msleep(500);
db.exec(m_Query);
}
void cExecThread::run()
{
msleep(500);
QSqlDatabase db = m_Database;
db.exec(m_Query);
}
To copy to clipboard, switch view to plain text mode
In my class where I need this exec() I do it like this:
{
if(db.isValid() && m_Connected)
{
query += TableName + "` WHERE `BusNr` = '";
query += BusNr += "';";
Exec(query);
//sql_query.exec(query);
CheckSqlError();
//qDebug() << query;
}
}
void cDatabase::RemoveBusNr(QString TableName, QString BusNr)
{
if(db.isValid() && m_Connected)
{
QSqlQuery sql_query(db);
QString query = "DELETE FROM `";
query += TableName + "` WHERE `BusNr` = '";
query += BusNr += "';";
Exec(query);
//sql_query.exec(query);
CheckSqlError();
//qDebug() << query;
}
}
To copy to clipboard, switch view to plain text mode
And here is the implementation from my Exec()-Function:
void cDatabase
::Exec(QString query
) {
execThread.m_Database = db;
execThread.m_Query = query;
execThread.start();
int iCount = 0;
while(execThread.isRunning())
{
if(iCount < 5000)
iCount++;
else
{
execThread.terminate();
if(execThread.isFinished())
qDebug() << "Thread finished";
}
}
}
void cDatabase::Exec(QString query)
{
execThread.m_Database = db;
execThread.m_Query = query;
execThread.start();
int iCount = 0;
while(execThread.isRunning())
{
if(iCount < 5000)
iCount++;
else
{
execThread.terminate();
if(execThread.isFinished())
qDebug() << "Thread finished";
}
}
}
To copy to clipboard, switch view to plain text mode
But this doesn`t work very well - it works wrong and delayed my programm.
Bookmarks