Solved QQuickPaintedItem paint() report error that QObject::killTimer: Timers cannot be stopped from another thread kernel\qobject.cpp
-
My code is as follows:
void DrpltGyslPanel::paint(QPainter *painter) { view_->render(painter, boundingRect(), view_->viewport()->rect(), Qt::KeepAspectRatio); }
DrpltGyslPanel
is subclass ofQQuickPaintedItem
,view_
is instance ofQGraphicsView
.And I knowDrpltGyslPanel::paint
is called inQSGRenderThread
, but what is thisTimer
used for?
And this also caused child threads endless loop.
How can I kill timer exactly? Or one more step for what exactly caused child threads endless loop? -
QGraphicsView::addItem
will start a timer by default interval(2000ms) at here.QGraphicsView::render
will kill timer at here.When killing timer will estimate whether the current thread is thread timer lives to make sure timer usage is in the same thread.So we can not invokeQGraphicsView::render
inDrpltGyslPanel::paint
fromQSGRenderThread
.
The code is corrected as follows:void DrpltGyslPanel::update(const QRect &rect) { renderPixman = QPixmap(view_->viewport()->rect().size());//renderPixman is member variable QPainter painter(&renderPixman); view_->render(&painter, boundingRect(), view_->viewport()->rect(), Qt::KeepAspectRatio); QQuickPaintedItem::update(rect); }
And why which will caused child threads endless loop, that is
timerEvent
alaways triggered.