Qt 将 Unicode 命令行参数检测为问号
Qt detecting Unicode command line arguments as question marks
有时,当我构建 Qt C++ 应用程序(MinGW、Qt 5.7.0)并使用 Windows 10 中的参数打开它时,它会将 Unicode 参数检测为问号。我真的不知道什么时候,但我认为这取决于参数的长度以及参数中是否为空格。
例如:
>app.exe سلام
receives: سلام
>app.exe سلاممممم
receives: سلاممممم
>app.exe سلامممممم
receives: ?????????
>app.exe d:\خطا
receives: d:\???
>app.exe "d:\خطا دار"
receives: d:\خطا دار
>app.exe C:\Users\Reza\Desktop\خطا.txt
receives: C:\Users\Reza\Desktop\???.txt
>app.exe C:\Users\Default\Desktop\خطا.txt
receives: C:\Users\Default\Desktop\خطا.txt
我使用 QCommandLineParser 和 app.arguments() 进行了测试,但都遇到了同样的问题。
这是 MinGW 编译器 globbing 过程中的一个问题。根据QTBUG-84002 and MinGW Tips,在main()
函数上面加上这段代码就可以解决:
extern int _CRT_glob = 0; /* 0 turns off globbing; 1 turns it on */
有时,当我构建 Qt C++ 应用程序(MinGW、Qt 5.7.0)并使用 Windows 10 中的参数打开它时,它会将 Unicode 参数检测为问号。我真的不知道什么时候,但我认为这取决于参数的长度以及参数中是否为空格。
例如:
>app.exe سلام
receives: سلام
>app.exe سلاممممم
receives: سلاممممم
>app.exe سلامممممم
receives: ?????????
>app.exe d:\خطا
receives: d:\???
>app.exe "d:\خطا دار"
receives: d:\خطا دار
>app.exe C:\Users\Reza\Desktop\خطا.txt
receives: C:\Users\Reza\Desktop\???.txt
>app.exe C:\Users\Default\Desktop\خطا.txt
receives: C:\Users\Default\Desktop\خطا.txt
我使用 QCommandLineParser 和 app.arguments() 进行了测试,但都遇到了同样的问题。
这是 MinGW 编译器 globbing 过程中的一个问题。根据QTBUG-84002 and MinGW Tips,在main()
函数上面加上这段代码就可以解决:
extern int _CRT_glob = 0; /* 0 turns off globbing; 1 turns it on */