PDA

View Full Version : QwtDial and QThread



hassinoss
12th July 2014, 15:36
Hi,

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?

anda_skoa
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

Cheers,
_

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

void CSpeedoMeter::Tracer(unsigned char* pPacket)
{
while(m_bStart)
{

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

}

and i must call setValue() in thread.

ChrisW67
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.