PDA

View Full Version : QFtp not connecting?



budda
9th August 2011, 16:39
having some trouble getting QFtp object to connect...

I have private class members:


QLineEdit *ftpServerLineEdit;
QLineEdit *ftpUserLineEdit;
QLineEdit *ftpPasswordLineEdit;

QFtp *ftp;
QGraphicsView *internet;



but can't get a QPushbuttons connect private slot function to work with this:


void MainWindow::testConnect(){

ftp = new QFtp(this);

QString server = ftpServerLineEdit->text();
QString user = ftpUserLineEdit->text();
QString password = ftpPasswordLineEdit->text();

QUrl url(server);

if (!url.isValid() || url.scheme().toLower != QLatinString("ftp")){
ftp->connectToHost(server,21);
ftp->login(user, password);

if (ftp->state() == QFtp::LoggedIn){
internet->setStyleSheet(QString("background: url(:/images/Online.png);"));
}
else{
internet->setStyleSheet(QString("background: url(:/images/Offline.png);"));
}
}

} //end member function



this never goes through the last if when I know that the hostname, username, & password are correct... can anyone help me with this? I'm sifting through the ftp example.... Is this code not getting a response from the server? therefore, just going to the last if, and then it's always false?

budda
9th August 2011, 19:13
Solved it... forgot to connect the commandFinished(int,bool) SIGNAL to the ftp instance of QFtp... then I did the test with the ftp->state() == QFtp::LoggedIn in the SLOT funtion