QFtp list()
-
Hi,
How are you using it ?
-
Hi
Are you using the commandFinished signal ?
list() is async. -
@magguz
Like any other signal.
Connect it to your slot.
http://blackberry.github.io/Qt2Cascades-Samples/docs/qftp.html -
@mrjj said in QFtp list():
@magguz
Like any other signal.
Connect it to your slot.
http://blackberry.github.io/Qt2Cascades-Samples/docs/qftp.htmlHi,
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?
-
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))); -
@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()); -
@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#listint 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. :) -
@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. -
@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."
-
@magguz
HGi
its :listInfo(const QUrlInfo & i)
so syntax is not correctconnect(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.