I am programming with Graphics View Framework
. I use a customized class which inherit from QGraphicsView
to show QGraphicsScene
. I new QGraphicsScene
in main thread and new QGraphicsItem
in another thread. When I call scene.addItem()
--here QT will emit signal to scene and it is not allowed by QT. But if I write setMouseTracking(true)
in my QGraphicsView
that would correct the QT's error. Why?
My code:
//centralWidget.cpp
pGraphicsScene_ = new QGraphicsScene(this);
pMonitorView_ = new MonitorView(pGraphicsScene_);
//monitorView.cpp
MonitorView::MonitorView(QGraphicsScene *scene, QWidget *parent):
QGraphicsView(scene, parent)
{
setMouseTracking(true);//If I comment this line,will get error--for this I don't confuse but write this statement will correct error!
}
//another thread start by std::thread
pItem = new GoodsItem();
pGraphicsScene_->addItem(pItem);