PDA

View Full Version : QHostAddress



rjschirmer
14th September 2009, 21:26
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:


void MainWindow::on_btnTest_clicked()
{
QHostAddress gatewayAddress();

if (gatewayAddress.setAddress(ui->lineGwIpAddr->text())) {
QMessageBox msgBox;
msgBox.setText("IP Address is OK");
msgBox.exec();
}
else {
QMessageBox msgBox;
msgBox.setText("Bad IP Address");
msgBox.exec();
}
}

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.

Lykurg
14th September 2009, 21:55
try
QHostAddress gatewayAddress;
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().

rjschirmer
14th September 2009, 22:13
try
QHostAddress gatewayAddress;
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!