PDA

View Full Version : Using QSound::play("...") not working



Charvi
31st March 2012, 14:37
Hi all,

I have developed a small program which will play a tone on any Key press. Now when I runt he application on desktop it works fine. But when I cross compile it for my device and run the application there no sound output is achieved. I have used QSound::play("..."); for playing the sound. The file is a .wav file. It gives the following error:

get volume of audio device failed
Floating point exception

Any idea what the problem might be anybody??? I have read that QSound directly accesses the /dev/dsp on an embedded device. When I use aplay on my device the tone is played fine.

Edit: Do I need to put any specific library on the device. Right now I have put three as per my requirement which are QtCore QtGui and QtNetwork.

Help soon.

Charvi Mehta.

wysota
31st March 2012, 15:19
What platform are you targetting? On Unix QSound requires NAS. Better use Phonon instead.

Charvi
2nd April 2012, 11:43
Can't try with phonon right now. But what I assume is I will need to put the QtMultimedia library on my embedded device before I run the program. Is that it? Do I need anything else to run a program that uses the phonon?


Yes my embedded device uses the Unix platform.

wysota
2nd April 2012, 12:48
QtMultimedia nad Phonon are two separate things. Both will require you to have a proper version of GStreamer though.

Charvi
2nd April 2012, 14:04
okay. But why isn't there anything which can directly access the /dev/dsp and work?

wysota
2nd April 2012, 14:46
You can open /dev/dsp with QFile and stream data to it if you want.

Charvi
3rd April 2012, 08:09
okay I used a workaround due to lack of time to experiment. I used the system command from within Qt and used aplay utility.

Now I get a key press sound on every keypress which I have handled in the event filter; because there I use the system command. But what should I do for the keys which are not handled by the event filter and which are internally handled by Qt. Like I have used a QScrollArea. The scroll bar navigation takes place with the up and down arrow keys. This is internally handled by Qt and hence no sound is played here. Is there anyway I can play sound here also? Ofcourse there is a way. Can anybody point out please.

Please reply.

Charvi
3rd April 2012, 10:29
Please reply.

wysota
3rd April 2012, 11:07
Install an event filter on the application object and intercept key events there.

Charvi
3rd April 2012, 11:28
No but then I will have to write the code for all the basic key press events also. That will be tedious and not desirable. Like then I will have to write event for scrolling; that's not going to be as smooth as the internal handling. It will also increase the lines of code.

Reply soon.

wysota
3rd April 2012, 11:56
No but then I will have to write the code for all the basic key press events also.
No, you won't.

Charvi
3rd April 2012, 12:06
Could you please give me an example or explain in more detail.

"Install an event filter on the application object and intercept key events there. "

How exactly?

wysota
3rd April 2012, 12:11
Could you please give me an example or explain in more detail.

"Install an event filter on the application object and intercept key events there. "

How exactly?

Sorry, an example of what? You did read the docs on how event filters work and you have seen examples of event filters in the docs before writing your two last posts, right?

Charvi
3rd April 2012, 12:17
Right. So when I write that I have installed an event filter and I am writing the system command for all the key press events, it works; the sound is played when these particular events occur. My question was there are some events internally handled by Qt like the scrolling of the scroll bars of a QScrollArea. I do not get the key press sound over there and its obvious. Then you adviced to install event filter for those also. To which I replied that then once I override the basic Qt's event handling of a particular event I need to write the code for it. This means I need to write the code for the scrolling of the scroll bars of the QScrollArea also. Then you said "NO". I didn't understand your NO!!

wysota
3rd April 2012, 12:26
My question was there are some events internally handled by Qt like the scrolling of the scroll bars of a QScrollArea. I do not get the key press sound over there and its obvious.
I have no idea what you are talking about. All events are "handled internally by Qt". Qt doesn't handle any events "externally".

Then you adviced to install event filter for those also.
No, I haven't. I told you to install an event filter on the application object and not on any scroll area or anything like that.

Charvi
3rd April 2012, 12:33
By internally I meant by default. Like when we want to handle some events in our own way we install event filters. The events which we do not handle in them will be handled by Qt in a default way.

wysota
3rd April 2012, 12:39
Like when we want to handle some events in our own way we install event filters.
No, we reimplement event handlers. Event filters are for specific cases such as yours or for lazy people who don't care about quality of their code.


The events which we do not handle in them will be handled by Qt in a default way.
Next time please use the term "by default" and not "internally" if you want to say "by default". And now please install an event filter on the application object and have your problem solved.

Charvi
3rd April 2012, 12:43
I accept. Will take care next time.

BTW I don't get how event filters affect the quality of code?

wysota
3rd April 2012, 12:51
BTW I don't get how event filters affect the quality of code?
They can break encapsulation.