Results 1 to 4 of 4

Thread: QGraphicsItem + Threads = Crash ?

  1. #1
    Join Date
    Dec 2009
    Posts
    50
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default QGraphicsItem + Threads = Crash ?

    Hi all.

    I'm using QGraphicsItems in my scene. And from time to time I need to call QGraphicsItem->update() function.
    I call update function from different threads ( one thread per item, and only this thread calls update for this item + application event thread ).

    And form time to time (randomly) it crashes inside update() function ( voidQList<T>::append down to stack).

    Even if I use common Mutex for all calls of update ( so I have 2 threads calling update(): item thread + application event thread )
    I'm using QT 4.5.2 for Widows (VS 200.

    Does anybidy know this issue ?
    Thank you!

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsItem + Threads = Crash ?

    You may not use (or call methods of) QWidgets from any thread but the main thread. Calling update() on a QGraphicsItem in all probability leads to such a call.

    Try sending your main thread a signal instead and have the main thread call update.

    HTH

  3. The following user says thank you to caduel for this useful post:

    medved6 (6th December 2009)

  4. #3
    Join Date
    Dec 2009
    Posts
    50
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsItem + Threads = Crash ?

    I thought that update just schedulel paint...
    So are you saing that to repaint item i need to send signal to main thread and after that make main thread just schedul paint event? Is there any way to schedul paint event directly from my thread ?

    Thank you for replay!

  5. #4
    Join Date
    Dec 2009
    Posts
    50
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsItem + Threads = Crash ?

    Thank you. It works now, I did as you said.

Similar Threads

  1. Crash: Heap corruption due to selectedRows()
    By Ankitha Varsha in forum Qt Programming
    Replies: 16
    Last Post: 1st October 2010, 00:55
  2. Why do some QWidgets create own threads?
    By donglebob in forum Qt Programming
    Replies: 5
    Last Post: 6th July 2010, 17:01
  3. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 10:31
  4. QString comparison gives wierd crash
    By supergillis in forum Qt Programming
    Replies: 0
    Last Post: 1st June 2009, 22:09
  5. Replies: 1
    Last Post: 25th February 2009, 00:34

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
  •  
Qt is a trademark of The Qt Company.