Results 1 to 5 of 5

Thread: Get hostname from linux system

  1. #1
    Join Date
    Apr 2012
    Posts
    43
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Get hostname from linux system

    Hi,
    I have one question because Im definitely missing something. I need to save system $HOSTNAME into QString. When I run echo $HOSTNAME from terminal I get the result. But from Qt when I try getenv("HOSTNAME") I get nothing. I tried the same with USERNAME and everything works fine. Then I tried print QProcess::systemEnvironment() and HOSTNAME variable wasnt in the result. It seems like my linux system does not export HOSTNAME for other applications or what? Is there a way to get HOSTNAME easily into QString?

    Thanks

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Get hostname from linux system

    Relying a environment variables is a bad idea anyway.

    Open Qt Assistant (or the Help panel in Qt Creator), go to the index tab and type "hostname"... the manual is your friend.
    Alternatively, since you started out with non-Qt functions, gethostname()

  3. #3
    Join Date
    Apr 2012
    Posts
    43
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Get hostname from linux system

    Thanks. I came across QHostInfo before, but when I tried to include it, compiler didnt find it. I think i must add path into gmake, but i dont know how If you can point me the right direction? gethostname works fine, thanks, but i'd like more using QHostInfo

  4. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Get hostname from linux system

    Qt Code:
    1. // in your pro file
    2. QT += network
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jul 2012
    Location
    Singapore
    Posts
    7
    Thanks
    3
    Qt products
    Qt3
    Platforms
    Windows Symbian S60

    Default Re: Get hostname from linux system

    It is very easy to ues it ....Creat a username...haha .....

Similar Threads

  1. How to change Linux system clock by Qt
    By wisconxing in forum Qt Programming
    Replies: 3
    Last Post: 7th September 2011, 07:04
  2. Linux - Support system's theme change
    By agarny in forum Qt Programming
    Replies: 2
    Last Post: 10th July 2011, 16:12
  3. file system embedded linux
    By danilodsp in forum General Discussion
    Replies: 0
    Last Post: 18th November 2010, 04:24
  4. QSslSocket hostname mismatch
    By eleanor in forum Qt Programming
    Replies: 7
    Last Post: 11th May 2009, 17:48
  5. QProcess / system call not working under linux. Why?
    By johnny_sparx in forum Qt Programming
    Replies: 12
    Last Post: 11th March 2006, 00:32

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.