[Qt-interest] QPainter: It is not safe to use drawPixmap() outside the GUI thread
Mihail Naydenov
mlists at ymail.com
Thu Oct 29 08:46:32 CET 2009
Its simple:
QPixmap is optimized for onscreen view it is stored in diff. way (on the graphics card memory for instance), its platform dependent, its not just a "a raw memory block". And also, I assume, when you draw() it you are acquiring some kind of context, shared with the whole onscreen painting system, part of the GUI thread, so, its not safe to interfere into the onscreen painting from other threads. (These a a bit my guesses, someone with more xp can correct me)
QImage on the other hand is just that "raw block" of memory that you need to draw onto.
And, and I said you can aways drawImage() instead of drawPixmap, its a bit slower, but can be "faster" for BIG images - no waiting for to Pixmap conversion.
As one last note, be ready to pay double memory consumption for the image, if you paint and draw (onscreen) in the same time. Either because of to Pixmap conversion or, if you are drawImage()ing, the implicit sharing will copy the entire image.
MihailNaydenov
----- Original Message ----
> From: Serge <mb0 at km.ru>
> To: qt-interest at trolltech.com
> Sent: Thu, October 29, 2009 8:00:48 AM
> Subject: Re: [Qt-interest] QPainter: It is not safe to use drawPixmap() outside the GUI thread
>
> Thank you for all answers.
>
> I want to understand, why i can not use QPixmap from the other thread.
>
> Ander wrote: "Yes. Don't do GUI painting outside the GUI thread. Ever."
>
> Can you please explain or give some links, what is GUI painting? What is
> the difference between GUI painting and non-GUI painting? Why when i use
> QPixmap i use GUI painting?
>
> Mihail Naydenov wrote:
> >
> >
> >
> > ----- Original Message ----
> >> From: Serge
> >> To: qt-interest at trolltech.com
> >> Sent: Wed, October 28, 2009 1:36:59 PM
> >> Subject: [Qt-interest] QPainter: It is not safe to use drawPixmap() outside
> the GUI thread
> >>
> >> Hello,
> >>
> >> I have QT application, which renders SVG on QPixmap in a separate
> >> thread. Separate thread is needed because rendering takes a lot of time.
> >> this application was developed in QT 4.3.3
> >> it worked fine without warnings.
> >>
> >> now i built it in QT 4.5.2
> >> when it works in debug output window i can see a lot of messages:
> >> QPainter: It is not safe to use drawPixmap() outside the GUI thread
> >>
> >> Is it critical warning?
> >> Can i leave rendering the same or i need to rewrite rendering so that it
> >> would not use QPixmap? What thread-safe alternative of using QPixmap?
> >
> > You should use QImage instead.
> >
> > Than you can drawImage() or QPixmap::fromImage() if you really need a pixmap
> (faster onscreen)
> >
> > MihailNaydenov
> >
> >
> >> Thank you!
> >>
> >> --
> >> Serge
> >> _______________________________________________
> >> Qt-interest mailing list
> >> Qt-interest at trolltech.com
> >> http://lists.trolltech.com/mailman/listinfo/qt-interest
> >
> >
> >
> >
>
> --
> Serge
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list