tags:

views:

347

answers:

1

Hello i am learning qt and trying to upload a file using QFtp i wrote the folowing code

this->connect(this->ftp, SIGNAL(done(bool)), this, SLOT(ftpDone(bool)));
this->connect(this->ftp, SIGNAL(dataTransferProgress(qint64, qint64)), this, SLOT(dataTransferProgress(qint64, qint64)));
this->connect(this->ftp, SIGNAL(stateChanged(int)), this, SLOT(stateChanged(int)));

.....

if(this->file.open(QIODevice::ReadWrite))
{
    this->ftp->setTransferMode(QFtp::Active);
    this->ftp->connectToHost(this->settings->getHost());
    this->ftp->login(this->settings->getUser(), this->settings->getPassword());
    this->ftp->cd(remoteFilePath);
    this->ftp->get(this->fileName, &this->file);
    this->ftp->close();
}

and it kind of stops it reports in dataTransferProgress that it is at 0/XXX but the slot is never invoked again (using the same code but with the get function i can download a file and it works without a problem) also the error that i get after the time out is QFtp::UnknownError.

+2  A: 

Assuming all the commands until get are successful, it's likely that you are closing the connection before get finishes. You should save the identifier returned by get and call close when the commandFinished signal is called with that identifier.

Note: Except setTransferMode all of the methods you used are asynchronous. They will be executed in the order that they are called, but since you aren't performing any error checking, it's possible for one to fail and the rest will still be attempted which might result in some confusion.

The proper way of doing this is to connectToHost first, if that's successful (you can track this with the commandFinished signal) call login etc.

Idan K
I agree, what you need to to is to build a state engine that reacts to the result (commandFinished) and then triggers the next command.
e8johan
i am doing something like this : void FtpCore::stateChanged(int state){ switch(state) { case QFtp::Unconnected: std::cout << "Not connected" << std::endl; break; ..... }}and the final state reported is QFtp::LoggedIn after that the slot void FtpCore::dataTransferProgress(qint64 done, qint64 total){ std::cout << done << "/" << total << std::endl;} is called but only once and then it freezes untill a timeout
Olorin
I can't quite understand the code but I think the original problem remains - you are calling `close` before `get` finishes.
Idan K