Audio element not working? How to play from resource?
I’m having problems using audio element from qml file located in resource file.
If my qml file is not in resource, the sound plays just fine. But instantly after I put the qml file to the resource, I can’t hear the audio element anymore. What should I do? I have tried putting the sound file to resource and to use it from file path…
11 replies
You can leave you sound file outside of resource file, then use
- viewer.rootContext()->setContextProperty("installPath", "file:///" + QCoreApplication::applicationDirPath() + "/");
in your main.cpp, make sure this line is before you setsource(“main.qml”)
In you qml code, just use
- Audio {
- id: playMusicAudio
- volume: 1.0
- source: installPath + "sound/youmusic.mp3"
- }
You need to have this in you app.pro file
- # Add more folders to ship with the application, here
- folder_01.source = qml/yourappname/sound
- DEPLOYMENTFOLDERS = folder_01
You must log in to post a reply. Not a member yet? Register here!




