Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QFtp::list() not functioning properly
Forum Updated to NodeBB v4.3 + New Features

QFtp::list() not functioning properly

Scheduled Pinned Locked Moved General and Desktop
qftpqftplistconnect
5 Posts 2 Posters 2.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jelicicm
    wrote on last edited by koahnig
    #1

    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?

    K 1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      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.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • J jelicicm

        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?

        K Offline
        K Offline
        koahnig
        wrote on last edited by
        #3

        @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.

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jelicicm
          wrote on last edited by jelicicm
          #4

          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 :(
          K 1 Reply Last reply
          0
          • J jelicicm

            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 :(
            K Offline
            K Offline
            koahnig
            wrote on last edited by
            #5

            @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++.

            Vote the answer(s) that helped you to solve your issue(s)

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved