1

I have a function to get the name of the computer as QString. While updating my program to Qt5 the function QString::fromAscii still doesn't exist anymore. How can I get it to 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;
    }
Frau Schmidt
  • 152
  • 11

1 Answers1

1

From the Qt documentation for the (obsolete) fromAscii function:

This function does the same as fromLatin1().

So, try this code:

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

Further documentation for the newer, replacement function.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83