C++ (Qt) ftp = new QFtp; qRegisterMetaType<QUrlInfo>("QUrlInfo"); connect(ftp, SIGNAL(listInfo(QUrlInfo)), this, SLOT(addToList(QUrlInfo))); ftp->setTransferMode(QFtp::Passive); ftp->connectToHost("ftp.host.ru"); ftp->login(login, password); QEventLoop loopFTP; connect(ftp, SIGNAL(commandFinished(int,bool)), &loopFTP, SLOT(quit())); loopFTP.exec(); connect(ftp, SIGNAL(commandFinished(int,bool)), &loopFTP, SLOT(quit())); loopFTP.exec(); connect(ftp, SIGNAL(commandFinished(int,bool)), &loopFTP, SLOT(quit())); loopFTP.exec(); ftp->list(); connect(ftp, SIGNAL(commandFinished(int,bool)), &loopFTP, SLOT(quit())); loopFTP.exec(); qDebug() << filesFTP; ftp->deleteLater(); return; void thread::addToList(const QUrlInfo &urlInfo){ qDebug() << "TEST addLIST" << urlInfo.name() << urlInfo.size() << urlInfo.owner() << urlInfo.lastModified(); // << urlInfo.lastModified().toString("MMM dd yyyy"); filesFTP.append(urlInfo.name());}
C++ (Qt)class MainWindow : public QMainWindow{ Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); private: Ui::MainWindow *ui; QStringList m_filesFTP; public slots: void addToList(const QUrlInfo &urlInfo) { m_filesFTP.append(urlInfo.name()); }}; ...MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this); QEventLoop *loop = new QEventLoop; QFtp *ftp = new QFtp; ftp->setTransferMode(QFtp::Passive); ftp->connectToHost(...); ftp->login(); connect(ftp, SIGNAL(listInfo(const QUrlInfo&)), this, SLOT(addToList(const QUrlInfo&))); connect(ftp, SIGNAL(done(bool)), loop, SLOT(quit())); ftp->list("/pub"); loop->exec(); qDebug() << m_filesFTP;}
C++ (Qt)QEventLoop loopFTP;QTimer::singleShot(15000, &loopFTP, SLOT(quit()));connect(ftp, SIGNAL(done(bool)), &loopFTP, SLOT(quit()));loopFTP.exec();