QUrl::fromLocalFile and relative path
-
wrote on 26 Jan 2013, 12:06 last edited by
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());
@ -
wrote on 26 Jan 2013, 19:25 last edited by
Thanks! It all worked perfectly fine! :)
-
wrote on 17 Nov 2013, 17:30 last edited by
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 ;)
-
wrote on 17 Nov 2013, 21:19 last edited by
[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!
-
wrote on 10 Jul 2014, 20:26 last edited by
@ 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?
-
wrote on 10 Jul 2014, 20:30 last edited by
Are there any messages if you start your app in a console ?
-
wrote on 10 Jul 2014, 20:33 last edited by
[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"
-
wrote on 10 Jul 2014, 20:46 last edited by
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 -
wrote on 10 Jul 2014, 21:13 last edited by
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!