Results 1 to 3 of 3

Thread: QHostAddress

  1. #1
    Join Date
    Sep 2009
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QHostAddress

    I am using QT Creator to create what I thought was a quick GUI application. I've narrowed down the problem to this:

    QLineEdit lineGwIpAddr should contain an IP address entered by the user (i.e. "127.0.0.1"). Right now when I click QPushButton btnTest I want to validate the IP address QString as such:

    Qt Code:
    1. void MainWindow::on_btnTest_clicked()
    2. {
    3. QHostAddress gatewayAddress();
    4.  
    5. if (gatewayAddress.setAddress(ui->lineGwIpAddr->text())) {
    6. QMessageBox msgBox;
    7. msgBox.setText("IP Address is OK");
    8. msgBox.exec();
    9. }
    10. else {
    11. QMessageBox msgBox;
    12. msgBox.setText("Bad IP Address");
    13. msgBox.exec();
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

    setAddress(const QString & address) should return true if the string was able to be parsed. But when I build I get the following error:

    .../imagedownload/mainwindow.cpp:22: error: request for member `setAddress' in `gatewayAddress', which is of non-class type `QHostAddress ()()'
    It looks like it is not recognizing QHostAddress as a class. I have included networking in my project by adding QT += network in the project file, so I'm not sure why I am still getting this error.

    I've attached the entire project to this post. Any help would be greatly appreciated.
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QHostAddress

    try
    Qt Code:
    1. QHostAddress gatewayAddress;
    To copy to clipboard, switch view to plain text mode 
    And be aware that it only checks the formal correctness, and not if the address exists and is reachable!

    You may also have a look at QLineEdit::inputMask or QLineEdit::setValidator().
    Last edited by Lykurg; 14th September 2009 at 21:59.

  3. The following user says thank you to Lykurg for this useful post:

    rjschirmer (14th September 2009)

  4. #3
    Join Date
    Sep 2009
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QHostAddress

    Quote Originally Posted by Lykurg View Post
    try
    Qt Code:
    1. QHostAddress gatewayAddress;
    To copy to clipboard, switch view to plain text mode 
    And be aware that it only checks the formal correctness, and not if the address exists and is reachable!

    You may also have a look at QLineEdit::inputMask or QLineEdit::setValidator().
    Doh! <headslap>

    I figured it would be something lame-brained such as that. Thanks!

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.