play a sound in application



  • 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();
    }
    


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



  • @VRonin
    i add the multimedia with this code

    QT       += multimedia
    


  • 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");
    }



  • What system are you running? Widows?



  • Hi
    @VRonin
    Yes i am using windows.



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



  • 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
    thanks a lot :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.