** qt5.9.1 添加音效后,播放无声音,什么原因?**
声音文件是翻金币游戏中找的。以下代码,在编译运行时,点按钮无声音,哪里错了呢?
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include
#include
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QPushButton *btn1= new QPushButton(this);
QPushButton *btn2= new QPushButton(this);
QPushButton *btn3= new QPushButton(this);
btn1->move(20,20);
btn2->move(btn2->width()+30,20);
btn3->move(btn3->width()*2+40,20);
btn1->setText("音效 1");
btn2->setText("音效 2");
btn3->setText("音效 3");
QSound *s1=new QSound(":/res/ConFlipSound.wav",this);
QSound *s2=new QSound(":/res/LevelWinSound.wav",this);
QSound *s3=new QSound(":/res/BackButtonSound.wav",this);
connect(btn1,&QPushButton::clicked,[=](){s1->play();});
connect(btn2,&QPushButton::clicked,[=](){s2->play();});
connect(btn2,&QPushButton::clicked,[=](){s3->play();});
}
MainWindow::~MainWindow()
{
delete ui;
}