QProcess running aplay
I'm using qt4.7.4 on an embedded Linux target.
I'm trying to add a sound when my touch panel is activated.
When a button is clicked I call the following:
cout << "close" << endl;
cout << "start" << endl;
cout << "done" << endl;
soundProcess is a class variable of type QProcess* and is opened on class instantiation.
I have tried far more than above, this is the simplest.
This works fine for a varying number of key clicks with about 1ms reported between "close" and "start" and 220ms between "start" and "done" (i.e. the length of the sound) until at some point I start getting about 30 seconds between "start" and "done" - which obviously kills my gui.
Anyone got any idea what might be going on - or any better ideas to achieve this?
I thank you in advance.
You can use QProcess::startDetached which runs in a separate process and returns immediately.
Why do you wait for it to finish at all? If it's just a sound for touch feedback then you don't need to establish an input/output channel or keep track of the process. Wouldn't it be better with a "fire and forget" style, i.e. "QProcess:startDetached":http://qt-project.org/doc/qt-5/qprocess.html#startDetached ?
msue - thanks for reply. Tried startDetached and it returns immediately as you suggested. After a number of 'plays' though I then get the error 'audio open error: Device or resource busy'.
In fact Chris, I started with your approach as this is what I want to end up with. I put the 30 second 'hang' down to the sound system being busy or something so thought I'd try waiting for it to complete as a test.
No nearer a solution yet but thanks...
The problem might lie with the default termination behaviour of the "aplay" program. You could experiment with some of its options (e.g. -d).