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. play a sound in application
QtWS25 Last Chance

play a sound in application

Scheduled Pinned Locked Moved Solved General and Desktop
playsoundapplicationqt 5.4
9 Posts 3 Posters 4.5k 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.
  • M Offline
    M Offline
    M4RZB4Ni
    wrote on 27 Apr 2016, 17:15 last edited by M4RZB4Ni
    #1

    Hi.
    i want to add a sound effect to my app
    that when i clicked on a push button that sound Run
    I Wrote this code but sound dose not play!
    what i must do?

     void MainWindow::on_pushButton_2_clicked()
    {
        QSound bts("/sounds/cartoon005.wav");
        bts.play();
    }
    

    Thanks
    M4RZB4Ni

    1 Reply Last reply
    0
    • V Offline
      V Offline
      VRonin
      wrote on 27 Apr 2016, 17:36 last edited by
      #2

      most likely it can't find the file. try using absolute path
      Did you deploy the multimedia plugin?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      M 1 Reply Last reply 27 Apr 2016, 17:52
      0
      • V VRonin
        27 Apr 2016, 17:36

        most likely it can't find the file. try using absolute path
        Did you deploy the multimedia plugin?

        M Offline
        M Offline
        M4RZB4Ni
        wrote on 27 Apr 2016, 17:52 last edited by
        #3

        @VRonin
        i add the multimedia with this code

        QT       += multimedia
        

        Thanks
        M4RZB4Ni

        1 Reply Last reply
        0
        • Y Offline
          Y Offline
          yuvaram
          wrote on 27 Apr 2016, 18:09 last edited by yuvaram
          #4

          Hi,

          Widget::Widget(QWidget *parent)
          : QWidget(parent)
          {
          glayout = new QGridLayout(this);
          pb_b1 = new QPushButton("sound");
          glayout->addWidget(pb_b1);
          connect(pb_b1,SIGNAL(clicked()),this,SLOT(SLT_playSound()));
          }

          void Widget:: SLT_playSound(){
          QSound::play("D:/pthinks/trash/button_sound/telugu4.wav");
          }

          Yuvaram Aligeti
          Embedded Qt Developer
          : )

          M 1 Reply Last reply 28 Apr 2016, 07:11
          0
          • V Offline
            V Offline
            VRonin
            wrote on 27 Apr 2016, 18:16 last edited by
            #5

            What system are you running? Widows?

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            0
            • Y Offline
              Y Offline
              yuvaram
              wrote on 27 Apr 2016, 18:20 last edited by
              #6

              Hi
              @VRonin
              Yes i am using windows.

              Yuvaram Aligeti
              Embedded Qt Developer
              : )

              1 Reply Last reply
              0
              • V Offline
                V Offline
                VRonin
                wrote on 27 Apr 2016, 18:22 last edited by
                #7

                make sure qtaudio_windows.dll and qtmedia_audioengine.dll plugins are deployed correctly

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                1 Reply Last reply
                0
                • Y Offline
                  Y Offline
                  yuvaram
                  wrote on 27 Apr 2016, 18:24 last edited by
                  #8

                  The above code working as expected. So i hope qtaudio_windows.dll and qtmedia_audioengine.dll plugins are deployed correctly. Please let me know if any issue with my code.

                  Yuvaram Aligeti
                  Embedded Qt Developer
                  : )

                  1 Reply Last reply
                  0
                  • Y yuvaram
                    27 Apr 2016, 18:09

                    Hi,

                    Widget::Widget(QWidget *parent)
                    : QWidget(parent)
                    {
                    glayout = new QGridLayout(this);
                    pb_b1 = new QPushButton("sound");
                    glayout->addWidget(pb_b1);
                    connect(pb_b1,SIGNAL(clicked()),this,SLOT(SLT_playSound()));
                    }

                    void Widget:: SLT_playSound(){
                    QSound::play("D:/pthinks/trash/button_sound/telugu4.wav");
                    }

                    M Offline
                    M Offline
                    M4RZB4Ni
                    wrote on 28 Apr 2016, 07:11 last edited by
                    #9

                    @yuvaram
                    thanks a lot :)

                    Thanks
                    M4RZB4Ni

                    1 Reply Last reply
                    0

                    9/9

                    28 Apr 2016, 07:11

                    • Login

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