PDA

View Full Version : Help on QFtp



Worf
21st June 2016, 11:40
Hi i all
i am a new user of QT i have a problem.
I connect to a ftp server using QFTP all work i need to put a file on this server.

ftp is a global variable when a call myroutine is loggedin on server.

i have connect this Signal to my slot:


connect(ftp,SIGNAL(done(bool)),this,SLOT(chkstat(b ool)));
connect(ftp,SIGNAL(commandFinished(int,bool)),this ,SLOT(CmdFinishSlot()));
connect(ftp,SIGNAL(commandStarted(int)),this,SLOT( CmdStartSlot()));
connect(ftp,SIGNAL(dataTransferProgress(qint64,qin t64)),this,SLOT(ftpProgress(qint64,qint64)));



When i try to execute the routine to put a file



void myroutine (QDir LDirToPut,QString RemoteDir)
{
QFileInfo FileList;
QByteArray buffer;


ftp->cd(RemoteDir);

foreach (FileList, LDirToPut.entryInfoList())
{
qDebug()<< FileList.fileName();

if(FileList.isFile())
{
CmdFinish=false;
QFile *file = new QFile(FileList.fileName());
file->open(QIODevice::ReadOnly);
buffer=file->readAll();
buffer=buffer.toBase64();
ftp->put(buffer,FileList.fileName(),QFtp::Binary);
while(CmdFinish){};
file->close();
};

};
}



i dont recive any signal and i put a 0 k byte file on server.The signal startcommand, finishcommeand and progress( with 0 byte in done and total) are recived by slot only when i finish the myroutyne.

Any help
Thanks

Sorry for my english

anda_skoa
21st June 2016, 11:51
QFtp, like most Qt IO classes, is event based, so its needs a running event loop to do its job.
Your while loop blocks the main thread, so it can't run its event loop.

If you really need the "one file at a time" approach, then instead of having a loop that waits for things that never happen, you need a nested event loop that exists when the file has been transferred, or at least you need to call processEvents() inside the loop.

So the quickest change would be calling processEvents() inside the loop, the cleanest would be not to attempt blocking IO.

Cheers,
_

P.S.: you are leaking that QFile pointer, better create the object on the stack.
PP.S.: are you sure you want to upload the base64 encoded content?

Worf
21st June 2016, 12:01
i try to don't use the while but the result is the same.I need "one file at a time" aproach but I can not know when a file i finish to trasfert because i don't have a signal to chek when it finish.

anda_skoa
21st June 2016, 13:14
You will get the signal as soon as you allow QFtp to actually do something.

Cheers,
_