I have a main thread and a QThread that are running in my C++/Qt application. At some point, I want to send data to the QThread and get a result back. I thought that using QPromise would be a good way to do this. However, all the docs I find usually pass the QPromise to the thread when the thread is created, and I’ve never seen it passed over a signal.
My working code passes it as a shared_ptr<QPromise<MyDataStruct>> through a queued signal to the secondary thread. This does work, although I’m not sure if it’s a reasonable way to do this. Is this ok or unsafe in any way? Is there a better way to do this? Is there a doc that I’ve missed talking about how to send a QPromise to an already-running QThread?