0

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

daniele86
  • 147
  • 3
  • 14
  • It is not clear what you are asking. I think there is some confusion of terms, e.g. a `class` is a type and as such cannot be called. A [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) would help. – nielsen Sep 21 '19 at 00:18
  • I think you probably want to use signals and slots if i understand your question. – qwerty9967 Sep 21 '19 at 00:36
  • Yes, it's possible. You can call a non-static member function of Class1 from Class2 – Thomas Sablik Sep 21 '19 at 00:50

1 Answers1

2

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

Eelke
  • 20,897
  • 4
  • 50
  • 76