PDA

View Full Version : Problem with QFtp



schnudl
25th March 2015, 15:39
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 */
/************************************************** ***********/
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;
}

anda_skoa
25th March 2015, 16:34
Check the return values of the connect() statement and also check if you see a warning during runtime about connect failing.

Cheers,
_

schnudl
26th March 2015, 08:13
Hello !

Return value is a positive number, referring to a command id.
Actually, x is 1, 2, 3, ....

No errors or warnings are emmited.

Regards, Michael

anda_skoa
26th March 2015, 09:17
Return value is a positive number, referring to a command id.

connect() returns a bool



No errors or warnings are emmited.

Since you are on Windows (according to your profile), do you have


CONFIG += console

in your .pro file?

Is the declaration of your Ftp class in a header or in a source file? If in a header, is it listes in HEADERS in your .pro?

Cheers,
_