Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/157.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在QMediaPlayer中使用资源文件_C++_Qt_Qmediaplayer - Fatal编程技术网

C++ 在QMediaPlayer中使用资源文件

C++ 在QMediaPlayer中使用资源文件,c++,qt,qmediaplayer,C++,Qt,Qmediaplayer,如何从.qrc资源文件加载.mp3文件以在QMediaPlayer中使用 这就是我目前所拥有的 QMediaPlayer *player = new QMediaPlayer; player->setMedia(QUrl::fromLocalFile(":/audio/theme.mp3")); player->play(); 参考资料.qrc: <RCC> <qresource prefix="/audio"> <file&g

如何从.qrc资源文件加载.mp3文件以在
QMediaPlayer
中使用

这就是我目前所拥有的

QMediaPlayer *player = new QMediaPlayer;
player->setMedia(QUrl::fromLocalFile(":/audio/theme.mp3"));
player->play();
参考资料.qrc:

<RCC>
    <qresource prefix="/audio">
        <file>theme.mp3</file>
    </qresource>
</RCC>

theme.mp3

theme.mp3位于项目目录中。

使用
m_player->setMedia(qrl(“qrc:/audio/theme.mp3”)


如果您使用的是Qt Creator,您可以通过按下侧栏中音频文件上的右键并选择
复制url“…”

当我尝试从资源播放时,可能会复制“我也没有声音”(Qt 5.5),将此url复制到剪贴板。如果我将文件复制到本地文件,那么它工作正常。回答得很好!非常感谢。当向路径添加
qrc:
时,请记住从localfile
中删除
:。