QFtp::list() not functioning properly
-
wrote on 19 May 2015, 06:58 last edited by koahnig
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?
-
wrote on 19 May 2015, 08:26 last edited by
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. -
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?
-
wrote on 19 May 2015, 09:03 last edited by 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 :(
-
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 :(
wrote on 19 May 2015, 09:12 last edited by@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++.
5/5