Skycoder42 / QtService

A platform independent library to easily create system services and use some of their features

Home Page:https://skycoder42.github.io/QtService/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WindowsServiceBackend doesn't work with the Unicode characters in the path

stephenlang84 opened this issue · comments

WindowsServiceBackend works fine when the path of the executable file contains only the latin characters, but it won't be able to find plugins when the path contains the non-latin characters. I can fix it as below code. But I'm not sure if this issue affect other parts of QtService or not.

Replace these lines

    const auto appDir = QFileInfo{QString::fromUtf8(argv[0])}.dir();
    qputenv("QT_PLUGIN_PATH", appDir.absolutePath().toUtf8());

To

    LPWSTR *szArglist;
    int nArgs;
    szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
    if( NULL == szArglist )
    {
       qCritical() << "CommandLineToArgvW failed";
       return 0;
    }
    const auto appDir = QFileInfo{QString::fromWCharArray(szArglist[0])}.dir();
    std::wstring path = appDir.absolutePath().toStdWString();
    _wputenv_s(L"QT_PLUGIN_PATH", path.c_str());

Your fix should be fine. As long as the plugin is found, the rest works independently of that. It is not an issue with the plugin itself but how Qt tries to find plugins