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. (SOLVED) Qt 5 and QFtp (qtftp)
QtWS25 Last Chance

(SOLVED) Qt 5 and QFtp (qtftp)

Scheduled Pinned Locked Moved General and Desktop
8 Posts 5 Posters 3.5k Views
  • 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.
  • V Offline
    V Offline
    ViniciusCampanha
    wrote on last edited by
    #1

    Hello.

    I need to work with QFtp because I want a list of files from a ftp, and QNetworkAccessManager don't have this function implemented.

    I installed the QFtp but I can't connect, the code is:

    @
    QFtp ftp = new QFtp();

    connect(ftp, SIGNAL(stateChanged(int)), this, SLOT(ftp_state_change_slot(int)));

    ftp->connectToHost(QString("ftp://localhost"),21);

    // while(terrama_ftp->state() != QFtp::HostLookup);
    @

    I know the execution of QFtp is asynchronous and I wrote a slot, but the slot is never called, and even when I tried wait with a while it don't change his state.

    Thanks for any help!

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Rondog
      wrote on last edited by
      #2

      Probably not helpful but just a comment.

      I thought QFtp was removed from Qt5. I used it in some Qt4 projects and was looking at alternatives for Qt5 because I read this somewhere.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        ckakman
        wrote on last edited by
        #3

        Hi,

        Are you sure that your signal-slot connection is OK? Why don't you check the returned value from connect().

        Are you running an event loop?

        1 Reply Last reply
        0
        • V Offline
          V Offline
          ViniciusCampanha
          wrote on last edited by
          #4

          Hello, thanks for reply!

          The connectToHost() is returning 1, and I think this is just the command ID.

          I'm not running a event loop, should I?

          Thanks!

          1 Reply Last reply
          0
          • JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #5

            [quote author="ViniciusCampanha" date="1421668693"]The connectToHost() is returning 1, and I think this is just the command ID.[/quote]ckakman meant Line #3 in your original post.

            [quote author="ViniciusCampanha" date="1421668693"]I'm not running a event loop, should I?[/quote]Yes, you need an event loop. The event loop responds to your stateChanged signal and runs your slot.

            Also, you must not have any infinite loops. Infinite loops block your slots from running.

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            0
            • V Offline
              V Offline
              ViniciusCampanha
              wrote on last edited by
              #6

              Thanks! It works!

              So, I put a QCoreApplication in my main:

              @QCoreApplication a(argc, argv);@

              And changed the code to connect:
              @
              QFtp ftp = new QFtp();

              QEventLoop loop;
              connect(ftp, SIGNAL(done(bool)), &loop, SLOT(quit()));

              connect(ftp, SIGNAL(stateChanged(int)), this, SLOT(ftp_state_change_slot(int)));

              ftp->connectToHost(QString("localhost"),21);

              loop.exec();
              @

              I discovered that in connectToHost I can't put host like "ftp://localhost", it must to be just "localhost".

              One last doubt, if in another part of code I want to work with ftp again, I will need another QEventLoop ?

              Thanks!

              1 Reply Last reply
              0
              • sierdzioS Offline
                sierdzioS Offline
                sierdzio
                Moderators
                wrote on last edited by
                #7

                [quote author="ViniciusCampanha" date="1421930032"]One last doubt, if in another part of code I want to work with ftp again, I will need another QEventLoop ?[/quote]

                No, one even loop is enough. In your snippet above you are running 1 loop and creating another: QCoreApplication has a built-in loop that is started when you call exec(). So in fact you do not need QEventLoop, it should be enough to just run a.exec() instead.

                (Z(:^

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  ViniciusCampanha
                  wrote on last edited by
                  #8

                  It works! Thanks!

                  The only way I could make it work was putting one QEventLoop at each time I need to pass a command to QFtp and wait for signal done().

                  It is because I dont know all the commands to pass at one time to QFtp, my program need to list the files at the ftp and then it will decide what to do with every file.

                  Thanks again!

                  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