biyanqing01
代码也可以升级为艺术
2017-12-05 11:16

Qt QSoundEffect播放声音文件不成功

5
  • qt

//这是头文件
#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函数也执行,为何声音还是播放不出来。

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐