gpt4 book ai didi

c++ - 如何打开名称带有 unicode 符号的文件

转载 作者:太空宇宙 更新时间:2023-11-03 10:21:34 25 4
gpt4 key购买 nike

我创建了一个 .exe 文件,并为该 .exe 文件关联了 .myFile 扩展名。我想双击任何 .myFile 文件并通过 .exe 打开该文件。为此,我做了以下工作:

int main(int argc, char *argv[])
{
QString fileName(QObject::tr(argv[1]));
if ( fileName != "" )
{
mainWin.loadFile(fileName);
}
..................
}

但是当我用 unicode 字符命名文件时(例如“Здравствуй.myFile”),您会看到“????????”而不是“Здравствуй”。如何解决这个问题呢?我知道这是已解决的问题,因为例如,MS Word 就是这样做的。

最佳答案

之前关注 int main(int argc, char** argv) 的答案不必要地复杂。 Qt 有更好的选择。

来自 Qt 文档:On Windows, the QApplication::arguments() are not built from the contents of argv/argc, as the content does not support Unicode. Instead, the arguments() are constructed from the return value of GetCommandLine().

因此,正确的答案是使用 qApp.arguments().at(1),它将在 QString 中为您提供 Unicode 文件名。

关于c++ - 如何打开名称带有 unicode 符号的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3226769/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com