View Full Version : QwtDial and QThread

12th July 2014, 15:36

I want to use QwtDial with QThread. it mean that i call setValue in the run() of QThread. but somtimes it crashes.

Please any idea?

12th July 2014, 21:48
That class name sounds like a widget, only the main thread (the one executing QApplication::exec()) is allowed to work with widgets.

If setValue() is a slot then you can call it through a cross-thread signal/slot connection, i.e. doing any data processing in the worker thread and the painting in the main thread


12th July 2014, 22:48
i don't understand. This my function run :

void CSpeedoMeter::Tracer(unsigned char* pPacket)

m_dValue = *(double*) (pPacket+m_XVoie.iPositionDataTraite);


and i must call setValue() in thread.

13th July 2014, 04:22
QwtDial:setValue() is a function on the widget object that exists in the main (UI) thread (assuming the dial is visible). You cannot safely call this function directly from another thread (through a pointer to the widget for example).

QwtDial:setValue() is also declared as a slot. You can have a QObject in the other thread emit a signal that you connect to the slot in the object in the main (UI) thread.

The widget cannot exist in the secondary thread as your code snippet suggests it does.