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)));
connect(m_query.data(), SIGNAL(commited(bool)), this, SLOT(process_stage_2(bool)));
To copy to clipboard, switch view to plain text mode
and then call
dataSession.commitQuery(m_query);
dataSession.commitQuery(m_query);
To copy to clipboard, switch view to plain text mode
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);
connect(m_query.data(), SIGNAL(commited(bool)), this, SLOT(process_stage_2(bool)));
dataSession.commitQuery(m_query);
To copy to clipboard, switch view to plain text mode
DataSession code:
void sk_efs_server::DataSession::commitQuery(QSharedPointer<EfsSqlQuery> query)
{
sqlMutex->lock();
sqlQueue->append(query);
sqlMutex->unlock();
sqlQueueFull->wakeAll();
}
void sk_efs_server::DataSession::commitQuery(QSharedPointer<EfsSqlQuery> query)
{
sqlMutex->lock();
sqlQueue->append(query);
sqlMutex->unlock();
sqlQueueFull->wakeAll();
}
To copy to clipboard, switch view to plain text mode
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();
}
void sk_efs_server::QueryCommiter::run()
{
QSharedPointer<EfsSqlQuery> query;
forever
{
sqlMutex->lock();
sqlQueueFull->wait(sqlMutex.data());
query = sqlQueue->dequeue();
sqlMutex->unlock();
query->exec();
}
exec();
}
To copy to clipboard, switch view to plain text mode
EfsSqlQuery code:
bool sk_efs_server::EfsSqlQuery::exec()
{
bool cted = m_query->exec();
emit commited(cted);
return cted;
}
bool sk_efs_server::EfsSqlQuery::exec()
{
bool cted = m_query->exec();
emit commited(cted);
return cted;
}
To copy to clipboard, switch view to plain text mode
Why is the signal never caught in my server thread even though it is emmited by EfsSqlQuery?
Thanks in advance.
Bookmarks