PDA

View Full Version : QSqlQuery queue notification when finished



kovariadam
17th October 2010, 09:42
Hi,
I'm building a server application that has multiple sources of input and needs to run queries in the background. I have following design:
DataSession: QObject - this class adds queries into QQueue and wakes QueryCommiter class, which is derived from QThread and runs queries.
Next class is EfsSqlQuery, derived from QObject, containing 1 QSqlQuery object, and one method, exec(), which runs the query and emits signal commited().

The question is, I want to catch the signal in my server application like this:

connect(m_query.data(), SIGNAL(commited(bool)), this, SLOT(process_stage_2(bool)));
and then call

dataSession.commitQuery(m_query);
which, as I described above, adds query to the queue and notifies the QueryCommiter class, that calls exec method of QSqlQuery and emits the signal.

The slot(process_stage_2(bool)) is never executed, though. But the SIGNAL IS emitted in the EfsSqlQuery!

I'll try to attach some relevant code:
Server code:

connect(m_query.data(), SIGNAL(commited(bool)), this, SLOT(process_stage_2(bool)));

dataSession.commitQuery(m_query);

DataSession code:

void sk_efs_server::DataSession::commitQuery(QSharedPoi nter<EfsSqlQuery> query)
{
sqlMutex->lock();
sqlQueue->append(query);
sqlMutex->unlock();

sqlQueueFull->wakeAll();
}

QueryCommiter code:

void sk_efs_server::QueryCommiter::run()
{
QSharedPointer<EfsSqlQuery> query;

forever
{
sqlMutex->lock();
sqlQueueFull->wait(sqlMutex.data());
query = sqlQueue->dequeue();
sqlMutex->unlock();

query->exec();
}

exec();
}

EfsSqlQuery code:

bool sk_efs_server::EfsSqlQuery::exec()
{
bool cted = m_query->exec();

emit commited(cted);

return cted;
}


Why is the signal never caught in my server thread even though it is emmited by EfsSqlQuery?

Thanks in advance.

kovariadam
18th October 2010, 14:58
Connecting the SIGNAL as Qt::QueuedConnection doesn't help. Is there any way to debug SIGNALs ?