QFtp::list() not functioning properly



  • I have a good piece of software that uses NetworkAccessManager to download some files from a certain FTP server. Problem is, up until now, it was OK for the addresses of those files to be "hard coded" in the software.

    Now I first need to get list of all files on that address of FTP server, and then select what file I want to be downloaded.

    Internet says I still have to use QFtp for this.

    I have created a small program to develop this phase, and problem occurred.

    QFtp *ftp=new QFtp();
    
    QObject::connect(ftp, SIGNAL(listInfo(const QUrlInfo &)), ftp, SLOT(printout(const QUrlInfo &)));
    
    ftp->connectToHost(address);
    if(ftp->login("user","password")) {
        printf("login success\n");
    } else printf("login fail");
    ftp->list();
    ftp->close();
    

    void QFtp::printout(const QUrlInfo &info) {
        printf("entered this function");
        printf("%s\n",info.name().toStdString().c_str());
        return;
    }
    

    It compiles with no errors or warnings. However, program never enters printout. I know for certain that my address is good, and that there are files on that ftp address!

    Does anyone have any idea as to what is happening?


  • Moderators

    Just added code block markers to your post. Those make your post with code easier to read.
    Please check out the "Editor markdown tags" respectively the Cheat sheet.


  • Moderators

    @jelicicm

    Assuming you have an event loop running it should work in my opinion.
    There is typically a delay in responding by the FTP server. Therefore, you cannot delete the QFtp object right away.



  • Hello @koahnig and thank you for your help and your reply!

    I did not implement any event loop, my code should call "printout" whenever list() finds a new item (if I understood it correctly).

    What kind of loop do you recommend?

    EDIT: It occurred to me that, maybe, list() is being called before login was done, so I done this>

    ftp->connectToHost(address);
    ftp->login("user","password");
    loop.exec();
    printf("login done\n"); ```
    
    But, still, not working :(

  • Moderators

    @jelicicm
    the exec() is typically called with a return at last position in main. Exec starts the event loop and continues until you quit the whole application.

    I recommend that you check out the example delivered with QtFtp
    This provides you a better start.

    When using Qt it is recommended to have a sound basis of C++. Your code looks as you are more familiar with C. It may help your understanding to go through some C++ tutorial, if you are not familiar with OOP and C++.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.