I want to use QFtp (I know, its deprecated, but I like it, because it's simple) within a console application (that means no GUI).
In order to have an event handler, I create a QCoreApplication (see below).
More or less, this approch is according to what I found in the web.
Whatever I do, the slot "commandStarted" is never executed, although the Ftp has pending commands.
I have no idea...
I would appreciate any help or hint !!!
Many thanks,
Michael
This is my Code:
...
/*************************************************************/
/* FTP CLASS */
/*************************************************************/
{
Q_OBJECT
public:
{
connect(this, SIGNAL(commandStarted(int)), this, SLOT(commandStarted_callback()));
}
public slots:
void commandStarted_callback(void);
void start();
private:
};
int start_ftp_thread()
{
int argc = 0;
/* create new ftp handler */
moc::Ftp* ftp = new moc::Ftp();
ftp->start();
/* start handler */
app.exec();
return 0;
}
/*************************************************************/
/* Entry point of FTP handling */
/*************************************************************/
void moc::Ftp::start()
{
int x;
_file
= new QFile( "D:\\junk\\qt.txt" );
x
= setTransferMode
(QFtp::Active);
x = connectToHost("10.9.16.159");
x = login("anonymous");
x = list();
x = get("SCHEDULE.CSV",_file);
x = close();
if (hasPendingCommands())
{
std::cout << "I have commands to execute..." << std::endl;
}
}
int start_ftp_thread()
{
int argc = 0;
/* create new ftp handler */
moc::Ftp* ftp = new moc::Ftp();
ftp->start();
/* start handler */
app.exec();
return 0;
}
/*************************************************************/
/* Called upon command started */
/*************************************************************/
void moc::Ftp::commandStarted_callback(void)
{
std::cout << "Command started..." << std::endl;
}
int main(void)
{
start_ftp();
return 0;
}
...
/*************************************************************/
/* FTP CLASS */
/*************************************************************/
class Ftp : public QFtp
{
Q_OBJECT
public:
Ftp(QObject* parent = 0)
{
connect(this, SIGNAL(done(bool)), QCoreApplication::instance(), SLOT(quit()));
connect(this, SIGNAL(commandStarted(int)), this, SLOT(commandStarted_callback()));
}
public slots:
void commandStarted_callback(void);
void start();
private:
QFile * _file;
};
int start_ftp_thread()
{
int argc = 0;
QCoreApplication app(argc, NULL);
/* create new ftp handler */
moc::Ftp* ftp = new moc::Ftp();
ftp->start();
/* start handler */
app.exec();
return 0;
}
/*************************************************************/
/* Entry point of FTP handling */
/*************************************************************/
void moc::Ftp::start()
{
int x;
_file = new QFile( "D:\\junk\\qt.txt" );
_file->open(QIODevice::ReadWrite);
x = setTransferMode(QFtp::Active);
x = connectToHost("10.9.16.159");
x = login("anonymous");
x = list();
x = get("SCHEDULE.CSV",_file);
x = close();
if (hasPendingCommands())
{
std::cout << "I have commands to execute..." << std::endl;
}
}
int start_ftp_thread()
{
int argc = 0;
QCoreApplication app(argc, NULL);
/* create new ftp handler */
moc::Ftp* ftp = new moc::Ftp();
ftp->start();
/* start handler */
app.exec();
return 0;
}
/*************************************************************/
/* Called upon command started */
/*************************************************************/
void moc::Ftp::commandStarted_callback(void)
{
std::cout << "Command started..." << std::endl;
}
int main(void)
{
start_ftp();
return 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks