Results 1 to 5 of 5

Thread: User recognition

  1. #1
    Join Date
    Feb 2007
    Posts
    16
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question User recognition

    Hi,

    I need to recognize the user by it's login name. I was thinking about use something like "net name" DOS command, but I'll make my application not very portable. There is in Qt some way to know what is the logged user name?

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

    Default Re: User recognition

    You can use the USER environment variable under Unix (which is not the best way to do it) or some system call like getuid() or geteuid(). Of course it surely won't work on Windows

  3. #3
    Join Date
    Oct 2006
    Posts
    60
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: User recognition

    Another not so great choice would be parsing QDir::homePath().
    There is also the USERNAME env variable in Windows and the aforementioned USER env variable in Unix.

    mAx

  4. The following user says thank you to maxpower for this useful post:

    eu.x (28th February 2007)

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

    Default Re: User recognition

    The problem with USER (at least under Linux) is that one can change its contents, so you can't rely on it:
    $ echo $USER
    wysota
    $ export USER=nonexistent
    $ echo $USER
    nonexistent
    Practically the same goes with homePath - you can't assume the path ends up with the user's login name. It's a convention, but not a rule.

  6. #5
    Join Date
    Mar 2006
    Posts
    140
    Thanks
    8
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: User recognition

    .NET has a namespace called System.Environment, you could download the Mono project source and see how they locate the details, and adapt it for Qt.

    This of course would only cover the windows world, but that's half your battle won
    Would be nice if Trolltech could include this feature in a future release.
    I'm afraid I have no idea how you'd do it on *nix.

Similar Threads

  1. Detecting user inaction
    By jrideout in forum Qt Programming
    Replies: 5
    Last Post: 10th December 2010, 08:37
  2. shutting down as user
    By safknw in forum Qt Programming
    Replies: 6
    Last Post: 27th November 2006, 10:28
  3. Replies: 1
    Last Post: 24th June 2006, 12:10
  4. Discard user input events in QEventLoop.
    By Ben.Hines in forum Qt Programming
    Replies: 2
    Last Post: 17th April 2006, 21:49
  5. linking user space and kernel space programs with qmake
    By zielchri in forum Qt Programming
    Replies: 9
    Last Post: 9th March 2006, 00: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.