Results 1 to 2 of 2

Thread: QPixmap: It is not safe to use pixmaps outside the GUI

  1. #1
    Join Date
    Aug 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QPixmap: It is not safe to use pixmaps outside the GUI

    Hi folks

    I came across the warning in the title (using QT unser Linux/X11 btw) but without any crash. I understand why and how this happens and read some posts about it (eg http://lists.trolltech.com/qt-intere.../msg00534.html).
    I've changed some code and now the message disappeared but I really want to understand if I did the right thing.

    This is the scenario when the warning occured:

    UI Main Thread
    Create the SubThread

    SubThread

    • created a Hash
    • created a QGraphicsView (widget), graphicScene. pixmapitem and setup everything
    • stored all pointers/object inside an object and pushed it inside the hash
    • called setPixmap
    • got warning about not using Pixmap outside the UI thread


    This Subthread can create several Widgets - thats the reason why I need the hash


    New scenario without warning

    UI Main Thread
    Create the hash
    Create the SubThread and pass the Hash

    SubThread

    • created a QGraphicsView (widget), graphicScene. pixmapitem and setup everything
    • stored all pointers/object inside an object and pushed it inside the hash
    • called setPixmap
    • NO MORE WARNING



    I'm not sure how the pixmap thing and UI painter work. As far as I understand the painter subsystem is not threadsafe and it COULD cause problems when using Pixmap outside the main thread.

    But why did the warning disappear when I create the (empty) hash in the main thread? Is this ok now? Or did the warning just disappear because I applied some dirty "trick" and QT can't see the problem anymore. A really "safe" solution would be using signals and slots beween UI and Sub Thread and use setPixmap in the UI thread, right?

    BR
    J

  2. #2
    Join Date
    Sep 2011
    Posts
    1,245
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPixmap: It is not safe to use pixmaps outside the GUI

    you shouldn't be creating any widgets outside of the gui thread. at all.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. Replies: 5
    Last Post: 7th February 2012, 22:13
  2. QPixmap: It is not safe to use pixmaps outside the GUI thread
    By bibhukalyana in forum Qt Programming
    Replies: 9
    Last Post: 16th May 2011, 07:30
  3. need to draw on pixmaps outside of the gui thread
    By Serenius in forum Qt Programming
    Replies: 2
    Last Post: 27th January 2009, 16:22
  4. Hande a *lot* of pixmaps (Qt4.4)
    By bunjee in forum Qt Programming
    Replies: 3
    Last Post: 20th May 2008, 10:08
  5. Problems with QActions and Pixmaps
    By ToddAtWSU in forum Qt Programming
    Replies: 8
    Last Post: 11th April 2007, 21:53

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.