daniele86
daniele86

Reputation: 147

Qt - run function on other thread

In my simple QApplication I have this scenario:

Class1 called from main thread.

Class2 called from other thread that contains a reference of Class1.

Is possible call Class1 function from Class2 using main thread?

I have tried with moveToThread without success. Thanks in advice, best regards.

Daniele

Upvotes: 0

Views: 427

Answers (1)

Eelke
Eelke

Reputation: 21993

The easiest way is probably to make the call through a signal to slot connection betweeen the to objects. Specify Qt::QueuedConnection or Qt::BlockingQueuedConnection as the connection type when making the connection. This type of connection will queue the signal on the thread of the receiving object.

For details see ConnectionType and connect

Upvotes: 2

Related Questions