I am looking for clarification to help me understand Qt multi threading and event loops with Qt 4.8. I would also add I am new to threading in general so that is part of my problem.
My current situation is I have a Qt app that needs to play sounds every so often using QTMultiMedia- QAudioOutput. I have two classes, MainGui and AudioWorker. I wish to call AudioWorker to "play()" a sound quite often.
Apparently QAudioOutput must have an event loop so the process doesn't end before the sound is played, and if this is done in the main class it will hold everything up. So I understand that threads will help.
Now if I understand threading correctly, the spawned thread cannot live longer than the function which created it unless it is detached somehow? So if I receive notification in my MainGui class to play a sound and I spawn a new thread via slot connection which calls play() in AudioWorker, wont the thread with the event loop just die once my MainGui notification function ends? If this is the case what is the point, either way the MainGui would need the event loop?
Surely I am missing something? Do I need to detach the thread somehow?I don't see much in Qt documentation on detaching. This whole process seems excessive just to play a simple sound.
updated
Resolved problem by creating QThread in play() function. Thread is does not prematurely exit until I emit signal.
Found a hidden but great example to follow at: https://nachtimwald.com/2015/05/02/effective-threading-using-qt/