Results 1 to 4 of 4

Thread: Using QWidget::update() from non-GUI thread

  1. #1
    Join Date
    Jun 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Using QWidget::update() from non-GUI thread

    Sometimes my application crashes in QWidget::update() that is performing in non-GUI thread.

    I am developing an application in which receives video frames from remote host and display them on QWidget.

    For this purpose I use libVLC library that gives to me a decoded image. I receive image in libVLC callback, that is performing in separate libVLC thread. In this callback I'm trying to perform QWidget::update() method. Sometimes application crashes, and callstack is somewhere in this method. Here is the my callback code:

    cpp Code:
    1. void VideoWidget::displayCB(void* picture)
    2. {
    3. QImage* image = reinterpret_cast<QImage*>(picture);
    4.  
    5. onScreenPixmapMutex_.lock();
    6. onScreenPixmap_ = QImage(*image);
    7. onScreenPixmap_.detach();
    8. onScreenPixmapMutex_.unlock();
    9.  
    10. delete image;
    11.  
    12. update();
    13. }
    To copy to clipboard, switch view to plain text mode 
    I know that GUI operations outside the main thread are not allowed in Qt. But according documentation QWidget::update() just schedules a paint event for processing when Qt returns to the main event loop and does not cause an immediate repaint.

    The questtion is: is the rule "GUI operations outside the main thread are not allowed" appliable for QWidget::update()? Does this operation belongs to "GUI operations"?

  2. #2
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using QWidget::update() from non-GUI thread

    QWidget::update() is not the culprit here. I think your code in some thread is trying to work on a datastructure which has been deleted.

  3. #3
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Using QWidget::update() from non-GUI thread

    You cannot directly call QWidget::update() from Non-GUI thread. One way is to emit a signal from Non-GUI thread and connect it QWidget::update() slot for the required widget

  4. #4
    Join Date
    Jun 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Using QWidget::update() from non-GUI thread

    Thank you.
    I've connected signal from Non-GUI thread to slot QWidget::update() , and crash does not reproduce.

Similar Threads

  1. Update GUI in a thread
    By olivier1978 in forum Qt Programming
    Replies: 3
    Last Post: 8th January 2011, 21:33
  2. Update GUI from another thread
    By Anne in forum Qt Programming
    Replies: 9
    Last Post: 14th July 2010, 15:08
  3. update a wigdet in a thread is no allow?
    By lanmanck in forum Qt Programming
    Replies: 8
    Last Post: 25th October 2009, 03:05
  4. update() in QWidget
    By salmanmanekia in forum Qt Programming
    Replies: 5
    Last Post: 28th July 2008, 08:03
  5. QWidget::update() qeustion
    By tanki95 in forum Qt Programming
    Replies: 7
    Last Post: 14th March 2008, 02:29

Tags for this Thread

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.