PDA

View Full Version : Qt GUI app hangs sometimes



rampage644
9th June 2011, 13:23
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.

wysota
9th June 2011, 15:46
There isn't much we can do without seeing code of all the threads.

rampage644
9th June 2011, 18:56
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:


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:


// 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

wysota
9th June 2011, 21:09
How about just substituting your worker thread with QtConcurrent::run()?

rampage644
10th June 2011, 06:22
Thanks, i'll try this solution. Will report on result.

rampage644
10th June 2011, 11:32
It apperas i've solved this issue without using QtConcurrent method.
replaced


setWindowTitle(s);

with


QMetaObject::invokeMethod(this,"setWindowTitle",Qt::QueuedConnection,
Q_ARG(QString, s));


After 15 minutes of testing there were no hangings.

wysota
10th June 2011, 11:39
Still, you'll get much better performance with QtConcurrent as you'll be using all available CPU power and not only one core.

rampage644
10th June 2011, 13:19
Thanks for advice. I'll take it into account.