How to get the login user name, system ideal time etc...?
-
Description:
- How can i get the current login user name ? and
- if the user goes to ideal mode then ideal mode starting time?
- ideal mode end time..
-
Hi,
AFAIK here is no Qt way in doing this.
ANd what is an Ideal mode? Do you mean idle? -
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. -
Thanks all...
-
Are you resolve your problem or not? If yes, how?
Because that is interesting for me too. -
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.).
-
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 -
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.
-
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.