Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QApplication::beep() - no sound on linux

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

Scheduled Pinned Locked Moved General and Desktop
15 Posts 4 Posters 20.1k Views
  • 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__ Offline
    _rth__ Offline
    _rth_
    wrote on last edited by _rth_
    #1

    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
    0
    • T Offline
      T Offline
      tarod.net
      wrote on last edited by
      #2

      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
      1
      • _rth__ Offline
        _rth__ Offline
        _rth_
        wrote on last edited by _rth_
        #3

        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
        0
        • T Offline
          T Offline
          tarod.net
          wrote on last edited by tarod.net
          #4

          @_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
          0
          • _rth__ Offline
            _rth__ Offline
            _rth_
            wrote on last edited by _rth_
            #5

            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
            0
            • _rth__ _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 Offline
              T Offline
              tarod.net
              wrote on last edited by tarod.net
              #6

              @_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
              0
              • _rth__ Offline
                _rth__ Offline
                _rth_
                wrote on last edited by
                #7

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

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  tarod.net
                  wrote on last edited by
                  #8

                  @_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
                  0
                  • _rth__ Offline
                    _rth__ Offline
                    _rth_
                    wrote on last edited by _rth_
                    #9

                    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
                    1
                    • _rth__ _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 Offline
                      T Offline
                      tarod.net
                      wrote on last edited by
                      #10

                      @_rth_ So is your problem resolved?

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

                      1 Reply Last reply
                      0
                      • _rth__ Offline
                        _rth__ Offline
                        _rth_
                        wrote on last edited by
                        #11

                        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
                        0
                        • _rth__ _rth_

                          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 Offline
                          T Offline
                          tarod.net
                          wrote on last edited by
                          #12

                          @_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
                          0
                          • T tarod.net

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

                            _rth__ Offline
                            _rth__ Offline
                            _rth_
                            wrote on last edited by
                            #13

                            @tarod.net Thanks for help!

                            Marking as solved.

                            1 Reply Last reply
                            0
                            • T Offline
                              T Offline
                              tsvigo
                              wrote on last edited by tsvigo
                              #14

                              You just need to install the SoX utility.
                              Create sound.sh:

                              #!/bin/bash
                              play sound.ogg
                              

                              ######################

                              #Not mp3
                              #include <QProcess>
                              QProcess().execute("sound.sh");
                              
                              JonBJ 1 Reply Last reply
                              0
                              • T tsvigo

                                You just need to install the SoX utility.
                                Create sound.sh:

                                #!/bin/bash
                                play sound.ogg
                                

                                ######################

                                #Not mp3
                                #include <QProcess>
                                QProcess().execute("sound.sh");
                                
                                JonBJ Offline
                                JonBJ Offline
                                JonB
                                wrote on last edited by JonB
                                #15

                                @tsvigo It seems a shame to run an external process, and have to install a program, each time you want to make a beep sound....

                                1 Reply Last reply
                                0

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved