qDebug( "locallhost: %s", qPrintable( QHostInfo::localHostName() ) ); //-- localhost nameQList<QHostAddress> addressList = QNetworkInterface::allAddresses();foreach( QHostAddress address, addressList ) qDebug( "yet another address: %s", qPrintable( address.toString() ) );//-- eth & lo addressesQList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();foreach( QNetworkInterface interface, interfaces ) qDebug( "yet another interface: %s", qPrintable( interface.hardwareAddress() );//-- macfor( int iCount = 0; iCount<QNetworkInterface::allInterfaces().count(); iCount++ ){ QNetworkInterface current = QNetworkInterface::interfaceFromIndex( iCount ); if( current.isValid() ) { QList<QNetworkAddressEntry> adresses = current.addressEntries(); for( int addrId = 0; addrId < adresses.count() ; addrId++ ) qDebug( "ip: %s", qPrintable( adresses.at( addrId ).ip().toString() ) ); }}
static QString login; if(login.isEmpty()) {#ifdef Q_OS_WIN QT_WA({ wchar_t buffer[256]; DWORD bufferSize = sizeof(buffer) / sizeof(wchar_t) - 1; GetUserNameW(buffer, &bufferSize); login = QString::fromUtf16((ushort*)buffer); }, { char buffer[256]; DWORD bufferSize = sizeof(buffer) / sizeof(char) - 1; GetUserNameA(buffer, &bufferSize); login = QString::fromLocal8Bit(buffer); });#else struct passwd* pwd = getpwuid(getuid()); if(pwd) login = QString(pwd->pw_name);#endif }
C++ (Qt)QString getUserName(){ return (qgetenv("USERNAME"));}