unable to get host name from QUrl::host() ?
#include <QUrl>
#include<QDebug>
#include<QFileInfo>
int main()
{
QUrl url("ftp.trolltech.com/mirrors");
if(!url.isValid())
qDebug() << "Url is invalid";
// url.setHost(url.toString());
// url.setHost(url.path());
qDebug() << "url.host() = " << url.host(); // not getting host name ......???????
qDebug() << "Url.path() = "<<url.path();
qDebug() << "url.scheme() = " <<url.scheme();
qDebug() << "QFileInfo(url.path()).fileName() = "<<QFileInfo(url.path()).fileName();
qDebug() << "url.port() = " << url.port(21);
// The other case tried by keeping scheme is as shown below .. still not getting hostname ..?????
QUrl url1("ftp:172.18.217.90");
qDebug() << "url1.host() = " << url1.host();
return 0;
}
Re: unable to get host name from QUrl::host() ?
Maybe you forgot the ftp:// or http:// in your url.
Code:
//QUrl url("ftp.trolltech.com/mirrors");
QUrl url
("ftp://ftp.trolltech.com/mirrors");
//QUrl url1("ftp:172.18.217.90");
QUrl url1
("ftp://172.18.217.90");
// or QUrl url1("http://172.18.217.90"); // btw, pinging this ip gives me request time out. qDebug() << "url1.host() = " << url1.host();