Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get the login user name, system ideal time etc...?
Forum Updated to NodeBB v4.3 + New Features

How to get the login user name, system ideal time etc...?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 7 Posters 14.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Basanta
    wrote on last edited by
    #1

    Description:

    1. How can i get the current login user name ? and
    2. if the user goes to ideal mode then ideal mode starting time?
    3. ideal mode end time..
    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      Hi,

      AFAIK here is no Qt way in doing this.
      ANd what is an Ideal mode? Do you mean idle?

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qxoz
        wrote on last edited by
        #3

        Well you can create your own functions
        for linux something like this:
        @#include<iostream>
        #include <cstdio>
        using namespace std;

        int main()
        {
        char text[255];
        FILE *name;
        name = popen("whoami", "r");
        fgets(text, sizeof(text), name);
        cout << "Name is : " << text;
        pclose(name);
        cout << endl;
        return 0;
        }
        @
        for windows using WinAPI
        @#include <iostream>
        #include <windows.h>
        using namespace std;
        int main()
        {
        char acUserName[100];
        DWORD nUserName = sizeof(acUserName);
        if (GetUserName(acUserName, &nUserName)) {
        cout << "User name is " << acUserName << "." << endl;
        cin.get();
        }
        return 0;
        }@

        It is not ready code for Qt, but it start point.
        Hope it's helpful.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Basanta
          wrote on last edited by
          #4

          Thanks all...

          1 Reply Last reply
          0
          • Q Offline
            Q Offline
            qxoz
            wrote on last edited by
            #5

            Are you resolve your problem or not? If yes, how?
            Because that is interesting for me too.

            1 Reply Last reply
            0
            • F Offline
              F Offline
              fluca1978
              wrote on last edited by
              #6

              The only solution is to implement a process that is machine/architecture dependent and gets back the information you need about the user (could it be username, uid, ecc.).

              1 Reply Last reply
              0
              • S Offline
                S Offline
                sreeram
                wrote on last edited by
                #7

                HI All

                I tried GetUserName to get username in to my qt application , but i am getting linker error GetUserName unresolved symbol.

                I know Advapi32.dll is the library for GetUserName ,but i dont know how to add this dynamic library to my qt application in WIN8

                Can any one help on this ??????

                Thanks
                Sreeram

                1 Reply Last reply
                0
                • IamSumitI Offline
                  IamSumitI Offline
                  IamSumit
                  wrote on last edited by
                  #8

                  hello sreeram
                  advapi32.dll is a MSDN library .
                  To work on MSDN library you have to include path as well as add .lib
                  into your .pro file of your MS SDKs.
                  see how to add library into Qt on net.
                  There are various link available.

                  hope it will help.

                  Be Cute

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mikeosoft
                    wrote on last edited by
                    #9

                    The nearest I could find to platform independent, in that it has no dependencies on platform specific libraries is

                    @QString name;
                    name = qgetenv(“USER”); // get the user name in Linux
                    If(name.isEmpty()) {
                    name = qgetenv(“USERNAME”); // get the name in Windows
                    }@

                    It reads the environment variable that holds the user name and I guess the Linux option would probably work on Apple platforms.

                    1 Reply Last reply
                    1

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved