mirror of
https://github.com/itay-grudev/SingleApplication.git
synced 2025-04-20 20:14:45 +08:00
Add support for Qt < 5.10
This commit is contained in:
parent
5fff2202b5
commit
00a2530465
@ -92,16 +92,25 @@ QString SingleApplicationPrivate::getUsername()
|
|||||||
DWORD usernameLength = UNLEN + 1;
|
DWORD usernameLength = UNLEN + 1;
|
||||||
if( GetUserNameW( username, &usernameLength ) )
|
if( GetUserNameW( username, &usernameLength ) )
|
||||||
return QString::fromWCharArray( username );
|
return QString::fromWCharArray( username );
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
|
||||||
|
return QString::fromLocal8Bit( qgetenv( "USERNAME" ) );
|
||||||
|
#else
|
||||||
return qEnvironmentVariable( "USERNAME" );
|
return qEnvironmentVariable( "USERNAME" );
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
#ifdef Q_OS_UNIX
|
#ifdef Q_OS_UNIX
|
||||||
QString username;
|
QString username;
|
||||||
uid_t uid = geteuid();
|
uid_t uid = geteuid();
|
||||||
struct passwd *pw = getpwuid( uid );
|
struct passwd *pw = getpwuid( uid );
|
||||||
if( pw )
|
if( pw )
|
||||||
username = QString::fromLocal8Bit( pw->pw_name );
|
username = QString::fromLocal8Bit( pw->pw_name );
|
||||||
if( username.isEmpty() )
|
if ( username.isEmpty() ) {
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
|
||||||
|
username = QString::fromLocal8Bit( qgetenv( "USER" ) );
|
||||||
|
#else
|
||||||
username = qEnvironmentVariable( "USER" );
|
username = qEnvironmentVariable( "USER" );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
return username;
|
return username;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user