스레드에서 QGraphicsScene
으로 QGraphicsView
을 업데이트해야합니다.스레드에서 장면 업데이트?
다음은 내가 뭘하고 있는지에 대한 pseudo'ish 코드 예제입니다.이 코드는 저에게 문제점 (런타임 오류)을 유발합니다.
내가 뭘 잘못하고 있고, 어떻게해야합니까?
메인 응용 프로그램 :
void Main::startThread()
{
view = new QGraphicsView(...);
thread = new MyThread(...);
connect(thread, SIGNAL(doSceneUpdate(QGraphicsScene*)), this, SLOT(updateScene(QGraphicsScene*)));
thread->start();
}
void Main::updateScene(QGraphicsScene *scene)
{
view->SetScene(scene);
view->show();
repaint();
}
스레드 : 사전에
void MyThread::run()
{
QGraphicsScene *scene = new QGraphicsScene(...);
while(1)
{
//draw stuff on the scene
emit doSceneUpdate(scene);
//some delay
}
감사합니다!
[편집] 오류 :
ASSERT failure in QCoreApplication::sendEvent: "Cannot send events to objects owned by a different thread. Current thread
3e53c0. Receiver '' (of type 'QGraphicsScene') was created in thread 1476cd18", file c:\Qt\qt-everywhere-opensource-src-4.8.2\src\corelib\kernel\qcoreapplication.cpp, line 501
런타임 오류 란 무엇입니까? – DeepBlack
Ive가 위 오류를 추가했습니다. 감사합니다 – thecoder