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 :)
Thanks! It all worked perfectly fine! :)
How can I do this on Qt 5.2?
There is no such function.
I think it has been moved to QFileInfo. Which makes sense, to be honest ;)
[quote author="sierdzio" date="1384709587"]I think it has been moved to QFileInfo. Which makes sense, to be honest ;)[/quote]
This works well, thank you!
@ QMediaContent menu(QUrl::fromLocalFile(QFileInfo("Menu.wav").absoluteFilePath()));
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.
Are there any messages if you start your app in a console ?
[quote author="andreyc" date="1405024207"]Are there any messages if you start your app in a console ?[/quote]
yes, there is:
defaultServiceProvider::requestService(): no service found for -"org.qt-project.qt.mediaplayer"
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
Thanks so much!
Your guide really helped!
I noticed that I had copied the wrong dll files when I used the windows search.
Now that I have the correct ones sound plays as it should!