Details
-
Bug
-
Resolution: Unresolved
-
P1: Critical
-
None
-
6.5.0
-
None
-
Windows 11 22H2
Both Qt 6.5.0 MinGW version provided by Qt Online Installer, and the MSYS2 version
Not sure if it's related but system locale is Chinese.
Description
Trying to use QMediaPlayer to play a file which its filename and/or filepath contain non-ascii characters under Windows will result playback failed.
Steps to reproduce:
1. Install Qt6 with Qt6 multimedia installed (currently `mingw64/mingw-w64-x86_64-qt6-multimedia 6.5.0-1 (mingw-w64-x86_64-qt6)`)
2. Save the following sample code to local, modify the path in `main.cpp` to an existing valid audio file on your machine, and ensure the path doesn't contain any non-ascii characters. (e.g. `R"path(D:\Users\Gary\Downloads\Music\sample.wav)path"`)
3. Compile the following sample program.
4. Run the program, the audio file should be able to play.
5. Re-do step 2, and modify the path to an existing file that contain non-ascii characters. (e.g. `R"path(D:\Users\Gary\Downloads\Music\sample - 副本.wav)path"`)
6. Compile the program again and run the program, now the audio file cannot be played.
Sample code:
CMakeLists.txt:
cmake_minimum_required (VERSION 3.9.5)
project (qt6mm)
set (CMAKE_AUTOMOC ON)
set (CMAKE_AUTORCC ON)
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core)
set (QT_MINIMUM_VERSION "6.5")
find_package(Qt${QT_VERSION_MAJOR} ${QT_MINIMUM_VERSION} REQUIRED
COMPONENTS Widgets Multimedia
)
set (EXE_NAME testbug)
add_executable (${EXE_NAME} main.cpp)
target_link_libraries (${EXE_NAME} Qt::Widgets Qt::Multimedia)
main.cpp:
#include <QApplication> #include <QAudioOutput> #include <QMediaPlayer> int main(int argc, char* argv[]) { QApplication app(argc, argv); auto path = QUrl::fromLocalFile(R"path(D:\Users\Gary\Downloads\Music\sample - 副本.wav)path"); // change the path here. QMediaPlayer * player = new QMediaPlayer; QObject::connect(player, &QMediaPlayer::sourceChanged, [&player](){ qDebug() << player->source(); }); QObject::connect(player, &QMediaPlayer::errorOccurred, [&player](){ qDebug() << player->errorString(); }); player->setAudioOutput(new QAudioOutput); player->setSource(path); player->play(); return app.exec(); }
When non-ascii characters are in filename or path, qDebug() will output:
"Could not open file" QUrl("file:///D:/Users/Gary/Downloads/Music/sample - 副本.wav")
Related: https://github.com/msys2/MINGW-packages/issues/16756