如何在Qt5中从Ascii获取QString::



我有一个函数可以将计算机的名称获取为QString。在将我的程序更新到Qt5时,函数QString::fromAcii仍然不存在。如何将其发送到QString?

QString AppConfig::GetMachinename()
{
char* buf = new char[512];
DWORD size;
int res;
QString machineName;
if ((res = GetComputerNameA(buf, &size)))
{
machineName = QString::fromAscii(buf, size);
}
else
machineName = "FALSE!";
return machineName;
}

来自(过时的(fromAscii函数的Qt文档:

此函数的作用与fromLatin1((相同。

所以,试试这个代码:

//...
if ((res = GetComputerNameA(buf, &size)))
{
machineName = QString::fromLatin1(buf, size);
}

更新的替换功能的进一步文档。

最新更新