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()
Qt 6.11 is out! See what's new in the release blog

QFtp list()

Scheduled Pinned Locked Moved Unsolved General and Desktop
30 Posts 3 Posters 20.6k Views 2 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.
  • M magguz

    @mrjj said in QFtp list():

    @magguz
    Like any other signal.
    Connect it to your slot.
    http://blackberry.github.io/Qt2Cascades-Samples/docs/qftp.html

    Hi,

    I have tried this now:

    ftp = new QFtp();
        ftp->connectToHost("ftp.example.com");
        ftp->login("","");
        ftp->list();
        connect(ftp, SIGNAL(commandFinished(int,bool)), this, SLOT(ftpCommandFinished()));
    

    The method connect seems to work. It calls ftpCommandFinished(). Inside ftpCommandFinished() I wrote this to set the text of a QTextEdit:

    ui->textEdit->append(ftp.list());
    

    But this causes an error. What does I make wrong?

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by mrjj
    #7

    Hi

    But this causes an error. What does I make wrong?

    First step is to show the actual error :)

    also
    the slot seems wrong. should have int and bool too
    connect(ftp, SIGNAL(commandFinished(int,bool)), this, SLOT(ftpCommandFinished(int,bool)));

    M 1 Reply Last reply
    0
    • mrjjM mrjj

      Hi

      But this causes an error. What does I make wrong?

      First step is to show the actual error :)

      also
      the slot seems wrong. should have int and bool too
      connect(ftp, SIGNAL(commandFinished(int,bool)), this, SLOT(ftpCommandFinished(int,bool)));

      M Offline
      M Offline
      magguz
      wrote on last edited by
      #8

      @mrjj said in QFtp list():

      Hi

      But this causes an error. What does I make wrong?

      First step is to show the actual error :)

      This error occurs:

      invalid user-defined conversion from 'int' to 'const QString&' [-fpermissive]
      ui->textEdit->append(m_ftp->list());

      mrjjM 1 Reply Last reply
      0
      • M magguz

        @mrjj said in QFtp list():

        Hi

        But this causes an error. What does I make wrong?

        First step is to show the actual error :)

        This error occurs:

        invalid user-defined conversion from 'int' to 'const QString&' [-fpermissive]
        ui->textEdit->append(m_ftp->list());

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #9

        @magguz
        Hi
        it says "why you give me int when i want qstring"
        what does list() return ?

        M 1 Reply Last reply
        0
        • mrjjM mrjj

          @magguz
          Hi
          it says "why you give me int when i want qstring"
          what does list() return ?

          M Offline
          M Offline
          magguz
          wrote on last edited by
          #10

          @mrjj

          I tried

          cout << ftp->list();
          

          and now it gives integers back

          mrjjM 1 Reply Last reply
          0
          • M magguz

            @mrjj

            I tried

            cout << ftp->list();
            

            and now it gives integers back

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #11

            @magguz
            Hi
            you really have to read docs as else it wont work for you :)
            http://doc.qt.io/archives/qt-4.8/qftp.html#list

            int QFtp::list(const QString & dir = QString())
            Lists the contents of directory dir on the FTP server. If dir is empty, it lists the contents of the current directory.
            
            The listInfo() signal is emitted for each directory entry found.
            
            The function does not block and returns immediately. The command is scheduled, and its execution is performed asynchronously. **The function returns a unique identifier which is passed by commandStarted() and commandFinished().**
            
            When the command is started the commandStarted() signal is emitted. When it is finished the commandFinished() signal is emitted.
            

            so it returns an unique identifier not a list. and it will send a signal listInfo() for each directory it finds.
            so its not like you call one function and get answer back at once.
            the operation is asynchronously. (if u dont know that means , please ask)
            its critical for understanding. :)

            M 1 Reply Last reply
            1
            • mrjjM mrjj

              @magguz
              Hi
              you really have to read docs as else it wont work for you :)
              http://doc.qt.io/archives/qt-4.8/qftp.html#list

              int QFtp::list(const QString & dir = QString())
              Lists the contents of directory dir on the FTP server. If dir is empty, it lists the contents of the current directory.
              
              The listInfo() signal is emitted for each directory entry found.
              
              The function does not block and returns immediately. The command is scheduled, and its execution is performed asynchronously. **The function returns a unique identifier which is passed by commandStarted() and commandFinished().**
              
              When the command is started the commandStarted() signal is emitted. When it is finished the commandFinished() signal is emitted.
              

              so it returns an unique identifier not a list. and it will send a signal listInfo() for each directory it finds.
              so its not like you call one function and get answer back at once.
              the operation is asynchronously. (if u dont know that means , please ask)
              its critical for understanding. :)

              M Offline
              M Offline
              magguz
              wrote on last edited by
              #12

              @mrjj

              Sorry, but I'm a beginner in C++/Qt. How I must handle the unique identifier that is returned? And what I must specify for "const QString" as the first parameter of QFtp::list?

              mrjjM 1 Reply Last reply
              0
              • M magguz

                @mrjj

                Sorry, but I'm a beginner in C++/Qt. How I must handle the unique identifier that is returned? And what I must specify for "const QString" as the first parameter of QFtp::list?

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #13

                @magguz
                Hi
                Dont be sorry. just practice reading docs. Its a must do for becoming PRO. :)
                It was not meant as lifted finger. just that u really need it :)

                The ID is just used to know what command a response belongs to.
                when command is done, it calls
                void QFtp::commandFinished(int id, bool error)

                so here the ID will be the same as the list() returns.

                so if you have issued multiple commands, that way you know what is what.

                The "const QString" is the name of a directory. but if you leave it empty, docs says it just mean
                "root"/top folder then. So if you dont need to only process a certain subfolder, i think leaving it empty is fine.

                M 1 Reply Last reply
                0
                • mrjjM mrjj

                  @magguz
                  Hi
                  Dont be sorry. just practice reading docs. Its a must do for becoming PRO. :)
                  It was not meant as lifted finger. just that u really need it :)

                  The ID is just used to know what command a response belongs to.
                  when command is done, it calls
                  void QFtp::commandFinished(int id, bool error)

                  so here the ID will be the same as the list() returns.

                  so if you have issued multiple commands, that way you know what is what.

                  The "const QString" is the name of a directory. but if you leave it empty, docs says it just mean
                  "root"/top folder then. So if you dont need to only process a certain subfolder, i think leaving it empty is fine.

                  M Offline
                  M Offline
                  magguz
                  wrote on last edited by
                  #14

                  @mrjj

                  And how I can get the content of a directory on a FTP-server as a string?

                  mrjjM 1 Reply Last reply
                  0
                  • M magguz

                    @mrjj

                    And how I can get the content of a directory on a FTP-server as a string?

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #15

                    @magguz
                    for each file it will send event listInfo() signal so you need to connect to that and build a string yourself if you want
                    that.
                    void QFtp::listInfo(const QUrlInfo & i)

                    so you get a QUrlInfo pr file.
                    you can ask for string with
                    QString QUrlInfo::name() const

                    "The listInfo() signal is emitted for each directory entry found."

                    M 1 Reply Last reply
                    0
                    • mrjjM mrjj

                      @magguz
                      for each file it will send event listInfo() signal so you need to connect to that and build a string yourself if you want
                      that.
                      void QFtp::listInfo(const QUrlInfo & i)

                      so you get a QUrlInfo pr file.
                      you can ask for string with
                      QString QUrlInfo::name() const

                      "The listInfo() signal is emitted for each directory entry found."

                      M Offline
                      M Offline
                      magguz
                      wrote on last edited by
                      #16

                      @mrjj

                      I have now created a second connect method and a function "addToList()" like this:

                      connect(m_ftp, SIGNAL(listInfo()), this, SLOT(addToList()));
                      

                      and now?

                      mrjjM 1 Reply Last reply
                      0
                      • M magguz

                        @mrjj

                        I have now created a second connect method and a function "addToList()" like this:

                        connect(m_ftp, SIGNAL(listInfo()), this, SLOT(addToList()));
                        

                        and now?

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #17

                        @magguz
                        HGi
                        its :listInfo(const QUrlInfo & i)
                        so syntax is not correct

                        connect(m_ftp, SIGNAL(listInfo(const QUrlInfo &), this, SLOT(addToList(const QUrlInfo &));
                        and change addToList so it takes that parameter.
                        For each file it calls it
                        and you can build your list or what you need.

                        M 1 Reply Last reply
                        0
                        • mrjjM mrjj

                          @magguz
                          HGi
                          its :listInfo(const QUrlInfo & i)
                          so syntax is not correct

                          connect(m_ftp, SIGNAL(listInfo(const QUrlInfo &), this, SLOT(addToList(const QUrlInfo &));
                          and change addToList so it takes that parameter.
                          For each file it calls it
                          and you can build your list or what you need.

                          M Offline
                          M Offline
                          magguz
                          wrote on last edited by
                          #18

                          @mrjj said in QFtp list():

                          @magguz

                          and change addToList so it takes that parameter.

                          how I can take the parameter into the addToList function?

                          mrjjM 1 Reply Last reply
                          0
                          • M magguz

                            @mrjj said in QFtp list():

                            @magguz

                            and change addToList so it takes that parameter.

                            how I can take the parameter into the addToList function?

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #19

                            @magguz
                            just change the addToList so it the real slot have a variable name.
                            (not in the connect. they are always without names)

                            void addToList(const QUrlInfo & file);

                            M 1 Reply Last reply
                            0
                            • mrjjM mrjj

                              @magguz
                              just change the addToList so it the real slot have a variable name.
                              (not in the connect. they are always without names)

                              void addToList(const QUrlInfo & file);

                              M Offline
                              M Offline
                              magguz
                              wrote on last edited by
                              #20

                              @mrjj

                              I changed the addToList() to addToList(const QUrlInfo & file)
                              Now I get an object named "file" for every directory entry, right?

                              mrjjM 1 Reply Last reply
                              0
                              • M magguz

                                @mrjj

                                I changed the addToList() to addToList(const QUrlInfo & file)
                                Now I get an object named "file" for every directory entry, right?

                                mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by mrjj
                                #21

                                @magguz
                                yes you get an URL object for each file
                                and the (QUrlInfo) file has a function called
                                name() that returns a QString.

                                http://doc.qt.io/archives/qt-4.8/qurlinfo.html

                                M 1 Reply Last reply
                                0
                                • mrjjM mrjj

                                  @magguz
                                  yes you get an URL object for each file
                                  and the (QUrlInfo) file has a function called
                                  name() that returns a QString.

                                  http://doc.qt.io/archives/qt-4.8/qurlinfo.html

                                  M Offline
                                  M Offline
                                  magguz
                                  wrote on last edited by
                                  #22

                                  @mrjj

                                  now I want to append the strings to a textEdit like this:

                                  ui->textEdit->append(file.name());
                                  

                                  but it doesn't work

                                  mrjjM 1 Reply Last reply
                                  0
                                  • M magguz

                                    @mrjj

                                    now I want to append the strings to a textEdit like this:

                                    ui->textEdit->append(file.name());
                                    

                                    but it doesn't work

                                    mrjjM Offline
                                    mrjjM Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #23

                                    @magguz
                                    in what way "doesn't work" ?
                                    What does it append?
                                    is the addToList called ?

                                    M 1 Reply Last reply
                                    0
                                    • mrjjM mrjj

                                      @magguz
                                      in what way "doesn't work" ?
                                      What does it append?
                                      is the addToList called ?

                                      M Offline
                                      M Offline
                                      magguz
                                      wrote on last edited by
                                      #24

                                      @mrjj said in QFtp list():

                                      @magguz
                                      in what way "doesn't work" ?
                                      What does it append?
                                      is the addToList called ?

                                      no it seems that addToList is not called. It appends nothing.

                                      mrjjM 1 Reply Last reply
                                      0
                                      • M magguz

                                        @mrjj said in QFtp list():

                                        @magguz
                                        in what way "doesn't work" ?
                                        What does it append?
                                        is the addToList called ?

                                        no it seems that addToList is not called. It appends nothing.

                                        mrjjM Offline
                                        mrjjM Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #25

                                        @magguz
                                        well check all your connects like
                                        qDebug() << "status:" << connect(xxxx); // xxxx being what u have
                                        and see they return true.
                                        also test that it does connect to the server. check errors and such.

                                        M 1 Reply Last reply
                                        1
                                        • mrjjM mrjj

                                          @magguz
                                          well check all your connects like
                                          qDebug() << "status:" << connect(xxxx); // xxxx being what u have
                                          and see they return true.
                                          also test that it does connect to the server. check errors and such.

                                          M Offline
                                          M Offline
                                          magguz
                                          wrote on last edited by
                                          #26

                                          @mrjj

                                          I found what was wrong. I changed

                                          ftp->login("","");
                                          

                                          in

                                          ftp->login();
                                          

                                          and it works. Thanks for your help!

                                          1 Reply Last reply
                                          1

                                          • Login

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