LPCWSTR path;
void WinApiLibrary::StartProcess(QString name)
{
path = name.utf16();
CreateProcess(path, NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
}C:\kursovaya\smc\winapilibrary.cpp:21:错误:从‘conversion *{LPCWSTR短无符号int*}到'LPCWSTR {aka const wchar_t*}’-fpermissive路径=name.utf16()的无效转换;
这段代码在QT4.8中工作,但现在我有了Qt5.2,而这段代码不起作用。这家伙怎么了?
发布于 2013-12-24 14:43:12
QString::utf16()返回const ushort*,这与const wchar_t*不同,所以您有编译错误。
您可能正在使用/Zc:wchar_t进行编译。如果您将其更改为/Zc:wchar_t-,它应该可以工作,因为在本例中,wchar_t类型将变成类型为16位整数。
在Visual中:Properties>Configuration>C/C++->将WChar_t视为构建在Type->No中。
或者添加reinterpret_cast<LPCWSTR>。
发布于 2014-10-14 16:54:48
我也有同样的问题(我使用的是QT5.3),这就是我如何修复它的方法:
QString strVariable1;
LPCWSTR strVariable2 = (const wchar_t*) strVariable1.utf16();发布于 2015-06-15 14:18:33
我正在使用Qt 5.2,我也遇到了同样的问题。我就是这样修好的:
QString sPath = "C:\\Program File\\MyProg";
wchar_t wcPath[1024];
int iLen = sPath.toWCharArray(wcPath);https://stackoverflow.com/questions/20762646
复制相似问题