我尝试将西里尔语单词作为命令行参数传递,但在子进程中,阅读时,我得到问号或单词 iconengines。我什至无法想象这意味着什么。这是父代码:
STARTUPINFO sti;
PROCESS_INFORMATION pi;
string strCMD = "child.exe ";
strCMD = strCMD + ui->stop->text().toUtf8().constData() + " " + to_string(ui->morale->value());
wstring CommandLine(strCMD.begin(), strCMD.end());
LPWSTR lpwCmdLine = &CommandLine[0];
ui->statusBar->showMessage(QString::fromStdString(strCMD));
ZeroMemory(&sti, sizeof(STARTUPINFO));
sti.cb = sizeof(STARTUPINFO);
CreateProcess(NULL, lpwCmdLine, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &sti, &pi);
阅读论据:
QString word = QString::fromStdString(argv[1]);
cout << word.toUtf8().constData() << endl;
// и таким способом, тот же результат
cout << argv[1];
据我了解,该错误类似于将 double 转换为 int 然后再转换为 float。QString 中有一个 Unicode 字符的字符串。当我们将其转换为字符串时,字符会以某种方式被截断(或损坏)。我们将损坏的字符写入 wstring。解决方案是立即在 QString 中创建一个命令行,然后立即使用 toStdWString 函数将其转换为 wstring: