How to get the login user name, system ideal time etc...?
-
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. -
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 -
-
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.