Results 1 to 8 of 8

Thread: Qt GUI app hangs sometimes

  1. #1
    Join Date
    Mar 2009
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question 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.
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt GUI app hangs sometimes

    There isn't much we can do without seeing code of all the threads.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2009
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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:
    Qt Code:
    1. void ThreadWorker::check_new_jobs()
    2. {
    3. /// locking mutex, will check queue
    4. mutex.lock ();
    5. while (!m_queue.isEmpty())
    6. {
    7. IJob* job = m_queue.dequeue();
    8.  
    9. mutex.unlock(); ///< will now do the job, unlock
    10. (*job)();
    11. delete job;
    12.  
    13. /// lock, will check queue again
    14. mutex.lock ();
    15. }
    16.  
    17. /// we've finished, unlock
    18. mutex.unlock ();
    19. }
    To copy to clipboard, switch view to plain text mode 

    And somewhere in my app:
    Qt Code:
    1. // update rcom parameter
    2. auto f = [=]()
    3. {
    4. app_set ().parameters_num ().updateObject (r06_TRIPNUM);
    5. ts::ParameterNum p;
    6. app_set ().parameters_num ().getObject (r06_TRIPNUM, p);
    7. p.val.val += 1;
    8. app_set ().parameters_num ().setObject (r06_TRIPNUM, p);
    9. };
    10. LambdaJob* job = new LambdaJob(f);
    11. app_set ().worker_thread ().add_job (job);
    To copy to clipboard, switch view to plain text mode 

    I have to understand the reason of freezes and then find erroneous piece of code

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt GUI app hangs sometimes

    How about just substituting your worker thread with QtConcurrent::run()?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2009
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt GUI app hangs sometimes

    Thanks, i'll try this solution. Will report on result.

  6. #6
    Join Date
    Mar 2009
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt GUI app hangs sometimes

    It apperas i've solved this issue without using QtConcurrent method.
    replaced
    Qt Code:
    1. setWindowTitle(s);
    To copy to clipboard, switch view to plain text mode 
    with
    Qt Code:
    1. QMetaObject::invokeMethod(this,"setWindowTitle",Qt::QueuedConnection,
    2. Q_ARG(QString, s));
    To copy to clipboard, switch view to plain text mode 

    After 15 minutes of testing there were no hangings.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Mar 2009
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt GUI app hangs sometimes

    Thanks for advice. I'll take it into account.

Similar Threads

  1. Mutlithreading hangs gui
    By thahir1986 in forum Newbie
    Replies: 2
    Last Post: 28th September 2010, 10:10
  2. Application Hangs in QTcpConnection
    By navi1084 in forum Qt Programming
    Replies: 1
    Last Post: 24th June 2009, 05:21
  3. Qt 4.5 Embedded hangs
    By nickich in forum Qt Programming
    Replies: 2
    Last Post: 2nd April 2009, 11:15
  4. QProcess hangs
    By Skizmo in forum Qt Programming
    Replies: 4
    Last Post: 8th March 2007, 10:27
  5. Using COM(ActiveX?) hangs up
    By gri in forum Qt Programming
    Replies: 4
    Last Post: 6th March 2007, 22:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.