You can use the following function to get current user name is Linux. I have tested this on Ubuntu and CentOS flavors but it should also work with other flavors without any issues.
Basically it uses whoami program to query the current user name and read the outputs of the process:
QString MyClass::getCurrentUserNameLinux()
{
QProcess process(this);
process.setProgram("whoami");
process.start();
while (process.state() != QProcess::NotRunning)
qApp->processEvents();
return process.readAll();
}