this's the QTread's subObject... and concrete it in main Thread....
the Runtime error as follow:
ASSERT failure in QCoreApplication::sendEvent: "Cannot send events to objects owned by a different thread. Current thread 176f0a8. Receiver '' (of type 'MainWindow') was created in thread 3976a0", file c:\ndk_buildrepos\qt-desktop\src\corelib\kernel\qcoreapplication.cpp, line 405 Invalid parameter passed to C runtime function. Invalid parameter passed to C runtime function.
class PaintThread : public QThread {
private:
QWidget* parent;
public:
~PaintThread() {}
PaintThread(QWidget* parent = 0) {
this->parent = parent;
}
void run() {
while (1) {
this->msleep(5000);
parent->repaint();
}
this->exec();
}
};
this's the MainFrame 's constructor :
MainWindow::MainWindow(QWidget *parent) :
QWidget(parent)
{
tankPoint = new QRect(50, 50, 30, 30);
this->show();
PaintThread * pt = new PaintThread(this);
pt->start();
}
the follow is the override paintEvent for MainWindow
void paintEvent(QPaintEvent*) {
QPainter p(this);
p.setPen(Qt::red);
p.setBrush(Qt::red);
p.drawEllipse(*tankPoint);
tankPoint->setLeft(200);
}
Can anyone tell me why?