[Qt-interest] QGraphicsItem and Threads
Andreas Pakulat
apaku at gmx.de
Mon Oct 19 19:57:14 CEST 2009
On 19.10.09 16:21:40, Ole Streicher wrote:
> Hallo Enrico,
>
> Enrico Ros <enrico.qt at email.it> writes:
> > the QBrush may allocate a QPixmap that is windowing-system dependant and
> > cannot be created outside of the main thread. As a rule of thumb: only use
> > QImages (or other non-gui classes) in threads.
>
> I thought that QGraphicsScene stuff is the non-gui part while
> QGraphicsView is the GUI representation?
Its all in QtGui, hence any of it may use GUI-only stuff.
> > Techniques for making the gui responsive while creating the items:
> > - if you have to load images, do it on threads and post a 'QImage *' to the
> > main thread. there you'll be able to convert it to QPixmap, or QBrush or
> > whatever
>
> I just want to change the colors of all my items depending on some
> sliders, mouse cursors etc.
As you found it you'll have to do that in the GUI thread.
> Ideal would be ofcourse if I could render the graphics view first to an
> image and then display the image as a whole instead of the view -- this
> would also avoid the flickering I get in the moment. Is this easily
> possible?
See QWidget::render(), a QImage is a QPaintDevice.
> > - if you have to load 100'000 items, divide them into chunks of.. say.. 100
> > items, and schedule the execution of the loading function with a zero-timer
> > - you can run QApplication::processEvents(), maybe excluding some kind of
> > events while creating the items.
> > - see Qt Quarterly 27: http://doc.trolltech.com/qq/qq27-responsive-guis.html
>
> OK, I will test and read this. What is a bit disappointing is that I
> have already a multithreading capable operating system on a
> multiprocessor kernel and I still have to implement some kind of
> cooperative multitasking by hand. OK, lets go back to the beginning of
> the 90ths :-)
Well, thats where the common graphical systems come from (X11 is even
older) so its no surprise that they're not thread-safe.
Andreas
--
Your reasoning powers are good, and you are a fairly good planner.
More information about the Qt-interest-old
mailing list