Hello every one, for several days I have been trying to resolve my problem but without success. I have my class instance which does "tough" computations in a separate thread continually and a QT GUI App which displays the progress.
I made a Timer in GUI App which regularly sends signal to my class instance to stop computations for a while and to update the QGraphicsScene with freshly computed data (access to raw data structures is protected with QMutex). When it is done, my instance sends signal to GUI (QMainWindow). Now it is time to display new data with "ui->graphicsView->repaint()". But it happens only once - only the first time repaint() on QGraphicsView is called, the other calls do nothing - like they are never called...but they are!
I draw/create my visual data (many QGraphicsRectItem-s) on the QGraphicsScene only once - in the mainWindow constructor. After that when the signal from mainWindow comes I iterate over QList of items in the QGraphicsScene a change their color according to new data. QGraphicsScene is bind to QGraphicsView of the mainWindow in the mainWindow constructor.
I am sure that the process of changing the colors of QGraphicsRectItem-s is ok, signals a slots are functioning. What can be my problem???
EDIT: I am using Xubuntu 11.10, Qt Creator 2.2.1 based on Qt 4.7.4
EDIT2: MyClass is member variable in mainWindow and the computational process goes in separate thread.
some code...
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
void MyClass::InitScene()
{
...
mScene = new QGraphicsScene();
QGraphicsRectItem * rect;
...
rect = new QGraphicsRectItem(x,y,a,b);
rect->setBrush(QColor(red,green,blue));
mScene->addItem(rect);
...
}
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
...
ui->graphicsView->setScene(MyClass->getScene());
...
QObject::connect(timer, SIGNAL(timeout()), MyClass, SLOT(sceneUpdateRequired()));
QObject::connect(MyClass, SIGNAL(sceneUpdated()), this, SLOT(slotRepaint()));
...
}
void MainWindow::slotRepaint()
{
qDebug() << "Repaint()";
ui->graphicsView->repaint();
}
void MyClass::sceneUpdateRequired()
{
qDebug() << "MyClass UpdateCanvas";
UpdateCanvas();
}
void MyClass::UpdateCanvas()
{
QGraphicsRectItem * el;
...
el = (QGraphicsRectItem*)mScene->items()[iter];
...
el->setBrush(QColor(newR, newG, newB));
...
emit(sceneUpdated());
}
|