How to parse data to running thread ?
-
I have created once queue that shared betweeen back end and front end thread
the front end thread is generated using sub class qthread.
for time being i am creating dummy data in that same thread and push that data into queue.
But Now i want to send data from c++ class to this running thread
What are the possible ways to do this thing ?
What is thread safe way to send data from c++ class to running qthread based sub class thread?
-
@Qt-embedded-developer The safest and easiest way is to use signals and slots. Then Qt will handle all synchronization logic.
If you want more customized solution, use standard thread syncing tools: mutexes, semaphores or if your data is very small - atomics. -
@sierdzio I have used signal and slot but my signal get emitted but slot is not get called
QObject::connect(_messageSendPtr.data(), SIGNAL(sigData(QString)), _guiComPtr.data(), SLOT(slotData(QString)), Qt::QueuedConnection);
what could be the reason?
-
@Qt-embedded-developer First: use functor based connections, they are much better.
Second: check the result ofconnect
- maybe it was not successful.
Third: make the connection after you move the object to thread (if you do thread moving). -
Duplicate https://forum.qt.io/topic/156213/what-should-be-best-mechanism-to-stop-and-start-same-thread-again
It would be nice if you did not double post so people try to answer in two places.....
-