在MacOS 10.10, Qt5.4, 使用QML运行一段简单的代码,发现一个奇怪的报错,记录一下,代码如下:
import QtQuick 2.3
import QtQuick.Window 2.2
import QtMultimedia 5.4
ApplicationWindow{
id: root
visiable:true
width:800; height:600
color:"#1F1F1F"
MediaPlayer{
id: player
source:"qrc:/logo.mp4"// source: "qrc:///logo.mp4"}
VideoOutput{
anchors.fill: parent
source: player
}
Component.onCompleted:{
player.play()}}
出现运行报错:
FigByteFlumeCustomURLOpen signalled err=-12936 (kFigByteFlumeError_BadState) (no provider) at /SourceCache/CoreMedia/CoreMedia-1562.238/Prototypes/FigHTTP/FigByteFlumeCustomURL.c line 1486
查找资料:
发现这个问题在Qt5.5.0版本被修复,主要的问题是:资源文件的路径不被识别
参考:
在Qt5.4版本的解决方式为:引入绝对路径
main.cpp:
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("applicationDirPath", QApplication::applicationDirPath());
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));main.qml:
ApplicationWindow{
id: root
visiable:true
width:800; height:600
color:"#1F1F1F"
MediaPlayer{
id: player
source:"file:///"+ applicationDirPath +"/Logo.mp4"}
VideoOutput{
anchors.fill: parent
source: player
}
Component.onCompleted:{
player.play()}}

发布评论