[SOLVED] QApplication::beep() - no sound on linux
-
Hi.
I have simple application, which should play sound on button click. I am using QApplication::beep() function (Qt 5.4.1). Everything works fine on Windows, but on linux (Ubuntu 12, Debian 7.8) no sound is played.
I am not aware of any limitation for linux platforms.
Is there anyone, who can help me find the solution? Thanks in advance.
-
I guess that it is. This is result from command:
pcspkr 12579 0
I have done some other tests and:
- command echo -e "\a" from terminal plays the sound
- if my application is console app and executed from terminal, sound can be heard
- if my application is GUI app, no sound is played
EDIT: the sound, which is played, is from System settings -> Sound -> Sound effects.
-
Hi.
Using
count << "\a" << endl;
gives sound only if application is executed from terminal. If it is launched e.g. from window (double-click) or from Qt Creator, no sound playing.I have also tried
system("echo -e \"\a\"");
, but the result is the same as above.EDIT:
UsingQSound::play("/usr/share/sounds/gnome/default/alerts/bark.ogg")
gives error:QSoundEffect(pulseaudio): Error decoding source
. Funny. -
@_rth_ Maybe QSound needs some extra Qt libraries.
Anyway, try using XBell.
I.e.:
#include <X11/Xlib.h> int main(int argc, char** argv) { Display *display=XOpenDisplay(NULL); XBell(display, 1000); XFlush(display); }
You will need to link X11 library:
gcc xbell.cpp -lX11
-
@_rth_ You have more information about XBell In this page:
https://bugzilla.redhat.com/show_bug.cgi?id=607393
But in any case, if your code is working in Windows and not in Linux, I think is a problem with Linux more than Qt.
My last recommendation is to use your more suitable solution among the following ones:
-
QMediaPlayer works (at least on Debian 7.8).
QMediaPlayer player; ... //player.setMedia(QUrl::fromLocalFile("/usr/share/sounds/gnome/default/alerts/bark.ogg")); //player.setMedia(QUrl::fromLocalFile("/usr/share/sounds/gnome/default/alerts/drip.ogg")); //player.setMedia(QUrl::fromLocalFile("/usr/share/sounds/gnome/default/alerts/glass.ogg")); //player.setMedia(QUrl::fromLocalFile("/usr/share/sounds/gnome/default/alerts/sonar.ogg")); player.setMedia(QUrl::fromLocalFile("/usr/share/sounds/freedesktop/stereo/bell.oga")); //this seems to be default alert player.setVolume(50); ... player.play();
-
-