0

I have a QThread that creates a QGraphicsSimpleTextItem. When I close my application I try to finish the thread and then terminate it.

if( !QThread::wait(1000) )
    QThread::terminate();

Everything is fine until I add a call to QGraphicsSimpleTextItem::setFont() in my thread. If I do so, Qt's internal QFontCache system is called and will start a QTimer (from my thread). Then when I terminate the QThread, killTimer is called (from the main) when Qt cleans up the event loops and I get the error:

QObject::killTimers: timers cannot be stopped from another thread

What should I do to avoid this problem? Shouldn't that be considered as a bug of the font caching mechanism? Thanks for your help.

Julien M
  • 657
  • 3
  • 10
  • 40
  • why does the QFontCache start a timer? can you explain in more detail what happens? – m.s. Apr 22 '15 at 07:49
  • Looks like it is for cache maintenance, I guess they don't want to keep a big cache if it's not required. It happens in qfont.cpp: void QFontCache::increaseCost(uint cost) – Julien M Apr 22 '15 at 08:08
  • 2
    I guess the problem is that you do GUI stuff in a non-GUI thread, see for example here: http://stackoverflow.com/questions/14545961/modify-qt-gui-from-background-worker-thread. You should move the call to `setFont()` to the GUI thread. – m.s. Apr 22 '15 at 08:14

0 Answers0