Search code examples
c++windowsqtmp3dll

QMediaPlayer not starting playback on Windows when started outside QtCreator


I wanted to accommodate myself with Qt5 and so I started a very small mp3 player. It compiles on Linux and Windows 7, both 64 bit.

When running on Windows however the selected mp3 file will only start playing when I start the program within QtCreator. When I start the standalone (shared compiled) EXE the program opens but instead starting the playback nothing happens (when debugging inside the IDE everything seems to work, sort of a Heisenbug I guess).

When looking at the file access in Processmonitor I see the directory scan, however when the MP3 should be opened nothing happens.

Maybe I missed to copy a DLL, however I have no hint which one is missing, so it may be another issue. Dependency Walker output (though it does not tell me which files/funcionts cause the errors, maybe I missed it):

Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module.
Error: Modules with different CPU types were found.
Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.

This is my directory content from where I try to start the EXE

  • folder "platforms" including: qminimal.dll, qwindows.dll
  • icudt49.dll, icuin49.dll, icuuc.49.dll
  • IEShims.dll (works without it, however Dependency Walker told its missing)
  • libEGL.dll
  • libgcc_s_sjlj-1.dll
  • libGLESv2.dll
  • libstdc++-6.dll
  • libwinpthread-1.dll
  • Qt5Core.dll, Qt5Gui.dll, Qt5Multimedia.dll, Qt5Network.dll, Qt5Widgets.dll
  • purr.exe

You can look at the complete source @ https://github.com/VashSan/purr - part of the source code where i start the playback:

void PurrWindow::playMedia()
{
    // [...]
    // QMediaPlayer is a member of PurrWindow:

    QUrl media = QUrl::fromLocalFile(selectedFile);
    player.setMedia(media);
    player.play();
}

I compiled the program once with MSVC2010 and once with Mingw with no difference.

I tried to google QMediaPlayer errors but most of them concern mobile platforms. However it did not leave a good impression of the QMediaPlayer to me, maybe I should look at a more reliable playback library. However if it would just start playback I'd be happy.


Solution

  • Use DLL Export Viewer to find out if your .exe is referring to the right .dlls.

    Sometimes people have more than one Qt/Phonon version installed and the PATH environment variable doesn't point to the directories where those DLLs are located.

    Also, make sure selectedFile has the full path to the file. It's a good idea to check if the path is valid after:

    selectedFile = fileDialog.getSelectedPath();
    

    with:

    QFile file( selectedFile );
    if( !file.exists() )
    {
      qDebug() << "!!! Invalid file: " << selectedFile;
      return;
    }