Results 1 to 6 of 6

Thread: Get user name

  1. #1
    Join Date
    Oct 2007
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Get user name

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Get user name

    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.

  3. The following user says thank you to wysota for this useful post:

    klipko (9th April 2008)

  4. #3
    Join Date
    Oct 2007
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Get user name

    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

  5. #4
    Join Date
    Apr 2008
    Location
    Michigan
    Posts
    6
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Get user name

    What about getenv("USERNAME")

  6. The following 2 users say thank you to jonman364 for this useful post:

    Ashkan_s (17th February 2013), maxoutlaw (21st November 2012)

  7. #5
    Join Date
    Aug 2007
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Get user name

    Hi
    #include <stdlib.h>
    U can use getenv("USER"); ///for MAc or Linux
    and
    getenv("USERNAME"); //for windows

    Thanks
    AMIT GUPTA

  8. #6
    Join Date
    Dec 2008
    Posts
    32
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Get user name

    also you could try call QProcess::systemEnvironment() and filter username from it's output.

Similar Threads

  1. Detecting user inaction
    By jrideout in forum Qt Programming
    Replies: 5
    Last Post: 10th December 2010, 07:37
  2. Replies: 1
    Last Post: 22nd June 2007, 19:46
  3. Replies: 1
    Last Post: 24th June 2006, 11:10
  4. linking user space and kernel space programs with qmake
    By zielchri in forum Qt Programming
    Replies: 9
    Last Post: 8th March 2006, 23:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.