QUrl::fromLocalFile and relative path
-
Hi, I'm tying to use the QMediaContent class to play some .wav files with QMediaPlayer (QSound doesn't work). When I use absolute paths for the files it works all fine, but I can't manage to get it working with relative paths (which I really need since I want to distribute my .exe). I need a little help here. Thanks :)
-
@
QUrl::fromLocalFile(QFile(yourRelativePath).absoluteFilePath());
@ -
I think it has been moved to QFileInfo. Which makes sense, to be honest ;)
-
@ QMediaContent menu(QUrl::fromLocalFile(QFileInfo("Menu.wav").absoluteFilePath()));
player->setMedia(menu);
player->play();@This works fine for me in Qt5.2.
The sound is played as long as I start the application via Qt. However if I try to open the exe in the build folder my program runs, but without the sound. I included all dll files that the exe file asked for.I already tried to put the wav file in a different folder than the build folder, but I couldn't get the sound to work anywhere.
Any suggestions?
-
You need to make sure that mediaservice plugins are available for your application.
I guess it should be in the PATH if you run your app on the same machine where Qt is installed or you must deploy your app and all necessary libraries if a machine does not have Qt installed.
See "Deploying Qt Applications":http://qt-project.org/doc/qt-5/deployment.html
If you run it on Windows that there is nice wiki page page about "Deploy an Application on Windows":http://qt-project.org/wiki/Deploy_an_Application_on_Windows