Results 1 to 4 of 4

Thread: Help on QFtp

  1. #1
    Join Date
    Jun 2016
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Help on QFtp

    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:
    Qt Code:
    1. connect(ftp,SIGNAL(done(bool)),this,SLOT(chkstat(bool)));
    2. connect(ftp,SIGNAL(commandFinished(int,bool)),this,SLOT(CmdFinishSlot()));
    3. connect(ftp,SIGNAL(commandStarted(int)),this,SLOT(CmdStartSlot()));
    4. connect(ftp,SIGNAL(dataTransferProgress(qint64,qint64)),this,SLOT(ftpProgress(qint64,qint64)));
    To copy to clipboard, switch view to plain text mode 


    When i try to execute the routine to put a file

    Qt Code:
    1. void myroutine (QDir LDirToPut,QString RemoteDir)
    2. {
    3. QFileInfo FileList;
    4. QByteArray buffer;
    5.  
    6.  
    7. ftp->cd(RemoteDir);
    8.  
    9. foreach (FileList, LDirToPut.entryInfoList())
    10. {
    11. qDebug()<< FileList.fileName();
    12.  
    13. if(FileList.isFile())
    14. {
    15. CmdFinish=false;
    16. QFile *file = new QFile(FileList.fileName());
    17. file->open(QIODevice::ReadOnly);
    18. buffer=file->readAll();
    19. buffer=buffer.toBase64();
    20. ftp->put(buffer,FileList.fileName(),QFtp::Binary);
    21. while(CmdFinish){};
    22. file->close();
    23. };
    24.  
    25. };
    26. }
    To copy to clipboard, switch view to plain text mode 


    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
    Last edited by anda_skoa; 21st June 2016 at 12:46. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Help on QFtp

    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?

  3. #3
    Join Date
    Jun 2016
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Help on QFtp

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Help on QFtp

    You will get the signal as soon as you allow QFtp to actually do something.

    Cheers,
    _

Similar Threads

  1. QFTP in LINUX
    By jsmith in forum Qt Programming
    Replies: 1
    Last Post: 2nd December 2009, 08:00
  2. Synchronous QFtp?
    By aarpon in forum Qt Programming
    Replies: 2
    Last Post: 26th October 2009, 10:28
  3. QFtp over QHttp
    By parusri in forum Qt Programming
    Replies: 1
    Last Post: 19th January 2009, 20:16
  4. Synchronizing QFtp
    By arun_vj in forum Qt Programming
    Replies: 0
    Last Post: 5th November 2008, 13:31
  5. Replies: 0
    Last Post: 23rd September 2007, 12:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.