PeCosta
PeCosta

Reputation: 537

QObject::startTimer: Timers cannot be started from another thread

I'm trying to handle a message that is received over a serial port in a concurrent manner. That is for each message that requires processing I want to use a different thread.

To do so I use the following code where receive_Message is connected to a signal that is emited for each message.

void Bat::receivePWrapper(Bat* bat, Message msg){
        bat->process_Message(msg);
    }
void Bat::receive_Message(Message msg){
       QFuture<void> future = QtConcurrent::run(Bat::receivePWrapper,this,msg);
   }

It apparently works but I get the message QObject::startTimer: Timers cannot be started from another thread for each message I receive.

The process_Message function manipulates GUI objects. Is that the issue here?

Upvotes: 2

Views: 5578

Answers (1)

Kevin Krammer
Kevin Krammer

Reputation: 5207

The function that runs in a secondary process must not access any GUI objects directly.

It can either emit signals connected to slots of these objects or use QMetaObject::invokeMethod() with connection type Qt::QueuedConnection to delegate the GUI object method call to the main thread.

Upvotes: 5

Related Questions