Qt-interest Archive, February 2007
QGraphcisScene in other threads
Message 1 in thread
Greetings All-
I am having a problem getting QGrpahicsView to repaint when I
add a new QGraphics Scene.
This works fine:
QGraphicsScene *oldScene(NULL);
while (true) {
QGraphicsScene *newScene = new QGraphicsScene();
// fill newScene with items.
ui.view->setScene(newScene);
if(oldScene != NULL) delete oldScene;
oldScene = newScene;
}
The Problem: Filling newScene with items is time consuming and
while doing so freezes the GUI. So I moved the creation of new scenes
to a "compute thread". In the compute thread I first create
the new scene like before, but I call moveToThread before I
send a signal to the GUI that a new scene has been created:
QGraphicsScene *newScene = sceneQueue->newScene();
// fill newScene with items.
newScene->moveToThread(QApplication::instance()->thread());
emit newSceneReady()
Back in the GUI thread I retrieve newScene and set it to the view.
This handoff of scenes is protected by a mutex in sceneQueue.
The GUI thread creates sceneQueue.
I can not get this new scene to display unless I cause a repaint by
covering and
then uncovering the window or by calling view->scale(1.01,1.01).
Calls to repaint and update have no effect.
Am I doing something wrong ?
Thanks in advance for any help,
-Dennis Flanigan
--
[ signature omitted ]