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); }DrpltGyslPanelis subclass ofQQuickPaintedItem,view_is instance ofQGraphicsView.And I knowDrpltGyslPanel::paintis called inQSGRenderThread, but what is thisTimerused 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::addItemwill start a timer by default interval(2000ms) at here.QGraphicsView::renderwill 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::renderinDrpltGyslPanel::paintfromQSGRenderThread.
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
timerEventalaways triggered.