1 Attachment(s)
Qt GUI app hangs sometimes
Good day.
Sorry for my english, it's not quite good.
i have multi-threaded application with network and db access (it's a client, not a server). Sometimes application hangs on startup/network connection establishing (doesn't matter).
I suppose there are some pitfalls with widget painting.. May be there is a code that tries to update (or paint) some widget outside main thread.
I know it's entirely my fault, not Qt. But i can't understand whats happening here and how to detect this bug.
PS Qt 4.7.1, Archlinux, Ubuntu, gcc 4.5.2, gcc 4.6.0
Backtrace is in attachments.
Re: Qt GUI app hangs sometimes
There isn't much we can do without seeing code of all the threads.
Re: Qt GUI app hangs sometimes
Are there any common pitfalls with widgets usage ('update()' routine call) in multithreaded app?
I've got worker thread which executes arbitrary pieces of code and main static thread. Here are some code snippets.
Worker thread has its event loop and a timer object which fires function:
Code:
void ThreadWorker::check_new_jobs()
{
/// locking mutex, will check queue
mutex.lock ();
while (!m_queue.isEmpty())
{
IJob* job = m_queue.dequeue();
mutex.unlock(); ///< will now do the job, unlock
(*job)();
delete job;
/// lock, will check queue again
mutex.lock ();
}
/// we've finished, unlock
mutex.unlock ();
}
And somewhere in my app:
Code:
// update rcom parameter
auto f = [=]()
{
app_set ().parameters_num ().updateObject (r06_TRIPNUM);
ts::ParameterNum p;
app_set ().parameters_num ().getObject (r06_TRIPNUM, p);
p.val.val += 1;
app_set ().parameters_num ().setObject (r06_TRIPNUM, p);
};
LambdaJob* job = new LambdaJob(f);
app_set ().worker_thread ().add_job (job);
I have to understand the reason of freezes and then find erroneous piece of code
Re: Qt GUI app hangs sometimes
How about just substituting your worker thread with QtConcurrent::run()?
Re: Qt GUI app hangs sometimes
Thanks, i'll try this solution. Will report on result.
Re: Qt GUI app hangs sometimes
It apperas i've solved this issue without using QtConcurrent method.
replaced
with
Code:
QMetaObject::invokeMethod(this,
"setWindowTitle",Qt
::QueuedConnection,
After 15 minutes of testing there were no hangings.
Re: Qt GUI app hangs sometimes
Still, you'll get much better performance with QtConcurrent as you'll be using all available CPU power and not only one core.
Re: Qt GUI app hangs sometimes
Thanks for advice. I'll take it into account.