diff options
-rw-r--r-- | singleapplication_p.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/singleapplication_p.cpp b/singleapplication_p.cpp index 705a980..ce50383 100644 --- a/singleapplication_p.cpp +++ b/singleapplication_p.cpp @@ -92,16 +92,25 @@ QString SingleApplicationPrivate::getUsername() DWORD usernameLength = UNLEN + 1; if( GetUserNameW( username, &usernameLength ) ) return QString::fromWCharArray( username ); +#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) + return QString::fromLocal8Bit( qgetenv( "USERNAME" ) ); +#else return qEnvironmentVariable( "USERNAME" ); #endif +#endif #ifdef Q_OS_UNIX QString username; uid_t uid = geteuid(); struct passwd *pw = getpwuid( uid ); if( pw ) 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" ); +#endif + } return username; #endif } |