I am using Qt Quick Application project in QT 5.2.1 in Linux Mint 13 and I want use relative path to my audio files, which are located in sounds folder of my project folder. Here is my
main.qml
import QtQuick 2.2
import QtQuick.Window 2.1
import QtMultimedia 5.0
Window {
visible: true
width: 360
height: 360
Audio{
id: sound
source: "sounds/1.mp3" //doesn't work
source: "file:../sounds/1.mp3" //also doesn't work
source: "file:/home/vlado/Qt projects/test521/sounds/1.mp3" //this works
}
MouseArea {
anchors.fill: parent
onClicked: {
sound.play()
}
}
Text {
text: qsTr("Play Sound")
anchors.centerIn: parent
}
}
Doesn't work means, that there is following error:
GStreamer; Unable to play - "" Error: "No URI set"
As you can see, everything is OK, if I use absolute path, but I would like to deploy this application and installation folder then will be different. That's why I want to use relative path. Here is my
test521.pro
TEMPLATE = app
QT += qml quick
SOURCES += main.cpp
RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Default rules for deployment.
include(deployment.pri)
Here is
my main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:///qml/main.qml")));
return app.exec();
}
How to set relative path instead of absolute?
Edit: Solution for QML: how to specify image file path relative to application folder doesn't work for me.