//这是头文件
#pragma once
#include
#include
#include "ui_QtGuiApplication2.h"
class QtGuiApplication2 : public QMainWindow
{
Q_OBJECT
public:
QtGuiApplication2(QWidget parent = Q_NULLPTR);
QSoundEffect _BackMusic;
void playsound();
private:
Ui::QtGuiApplication2Class ui;
};
//这是Cpp文件
#include "QtGuiApplication2.h"
QtGuiApplication2::QtGuiApplication2(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
_BackMusic = new QSoundEffect;
playsound();
}
void QtGuiApplication2::playsound()
{
_BackMusic->setSource(QUrl::fromLocalFile("Summer.mp3"));
_BackMusic->setLoopCount(QSoundEffect::Infinite);
_BackMusic->setVolume(0.9);
_BackMusic->play();
}
编译通过,断点调试playsound函数也执行,为何声音还是播放不出来。