Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [SOLVED] QApplication::beep() - no sound on linux

    General and Desktop
    2
    13
    17468
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • _rth_
      _rth_ last edited by _rth_

      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.

      1 Reply Last reply Reply Quote 0
      • T
        tarod.net last edited by

        Please, check if pcspkr module is currently loaded:

        $ lsmod | grep pcspkr
        

        "Individually, we are one drop. Together, we are an ocean."

        1 Reply Last reply Reply Quote 1
        • _rth_
          _rth_ last edited by _rth_

          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.

          1 Reply Last reply Reply Quote 0
          • T
            tarod.net last edited by tarod.net

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

            Could you change your code to use QSound?

            http://doc.qt.io/qt-5/qsound.html

            If you write

            cout << '\a';
            

            in your GUI application, is the beep played?

            "Individually, we are one drop. Together, we are an ocean."

            1 Reply Last reply Reply Quote 0
            • _rth_
              _rth_ last edited by _rth_

              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:
              Using QSound::play("/usr/share/sounds/gnome/default/alerts/bark.ogg") gives error: QSoundEffect(pulseaudio): Error decoding source. Funny.

              T 1 Reply Last reply Reply Quote 0
              • T
                tarod.net @_rth_ last edited by tarod.net

                @_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
                

                "Individually, we are one drop. Together, we are an ocean."

                1 Reply Last reply Reply Quote 0
                • _rth_
                  _rth_ last edited by

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

                  1 Reply Last reply Reply Quote 0
                  • T
                    tarod.net last edited by

                    @_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:

                    http://doc.qt.io/qt-5/audiooverview.html

                    "Individually, we are one drop. Together, we are an ocean."

                    1 Reply Last reply Reply Quote 0
                    • _rth_
                      _rth_ last edited by _rth_

                      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(); 
                      
                      T 1 Reply Last reply Reply Quote 1
                      • T
                        tarod.net @_rth_ last edited by

                        @_rth_ So is your problem resolved?

                        "Individually, we are one drop. Together, we are an ocean."

                        1 Reply Last reply Reply Quote 0
                        • _rth_
                          _rth_ last edited by

                          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.

                          T 1 Reply Last reply Reply Quote 0
                          • T
                            tarod.net @_rth_ last edited by

                            @_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.

                            "Individually, we are one drop. Together, we are an ocean."

                            _rth_ 1 Reply Last reply Reply Quote 0
                            • _rth_
                              _rth_ @tarod.net last edited by

                              @tarod.net Thanks for help!

                              Marking as solved.

                              1 Reply Last reply Reply Quote 0
                              • First post
                                Last post