Does QT have a method to get the user name? I've found methods similar in QHostInfo but nothing directly to retrieve the logged in user name.
Thanks.
QT version: 4.3.2
Does QT have a method to get the user name? I've found methods similar in QHostInfo but nothing directly to retrieve the logged in user name.
Thanks.
QT version: 4.3.2
No, it doesn't. What do you need it for? You should retrieve that using platform dependent means. You can use QDesktopServices::displayName(QDesktopServices::HomeLocation) and extract the username from the result, but it might fail for non-standard setups.
klipko (9th April 2008)
Thanks wysota. The short, my app reserves and releases a motion controller (Ethernet based). But there are times when other users may need to use that controller, so I've implemented an un-reserved feature...bump the current user off. I wanted to display a messagebox if the user is trying to un-reserve the device if it's reserved from another user but not if the current user was the one who reserved it. (Confused?) The best option is to look at the user login name but I think just comparing the machine names maybe good enough. I know this feature can and maybe abused and it's been much debated but if the customer asks ($$$), I shall create.
What do you mean by "might fail for non-standard setups"?
Last edited by klipko; 9th April 2008 at 23:18. Reason: Add in a question
What about getenv("USERNAME")
Hi
#include <stdlib.h>
U can use getenv("USER"); ///for MAc or Linux
and
getenv("USERNAME"); //for windows
Thanks
AMIT GUPTA
![]()
also you could try call QProcess::systemEnvironment() and filter username from it's output.
Bookmarks