⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

[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.

  • Please, check if pcspkr module is currently loaded:

    $ lsmod | grep pcspkr

  • I guess that it is. This is result from command:
    pcspkr 12579 0

    I have done some other tests and:

    1. command echo -e "\a" from terminal plays the sound
    2. if my application is console app and executed from terminal, sound can be heard
    3. if my application is GUI app, no sound is played

    EDIT: the sound, which is played, is from System settings -> Sound -> Sound effects.

  • @_rth_ I've been reading about your problem, and it seems a Qt/Linux issue.

    Could you change your code to use QSound?


    If you write

    cout << '\a';

    in your GUI application, is the beep played?

  • 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.

    Using QSound::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.


    #include <X11/Xlib.h>
    int main(int argc, char** argv)
            Display *display=XOpenDisplay(NULL);
            XBell(display, 1000);

    You will need to link X11 library:

    gcc xbell.cpp -lX11

  • I tried your example, compiled without any error, executed from terminal. Unfortunately no sound played.

  • @_rth_ You have more information about XBell In this page:


    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/freedesktop/stereo/bell.oga")); //this seems to be default alert

  • @_rth_ So is your problem resolved?

  • It hard to say ... I wanted to have platform independent, simple system alert to warn user about something. Right now, the only option is to add some sound (file) to app and use QMediaPlayer. QApplication::beep() is useless. It is not, what I expected.

  • @_rth_ Well, in my opinion, Qt and Linux have some things to talk about :) The fact is QApplication::beep() is not working in Ubuntu and Debian. QMediaPlayer is a good choice although you have to provide a file with your application.

  • @tarod.net Thanks for help!

    Marking as solved.

Log in to reply