Qt-interest Archive, March 2007
Event-queue problems
Message 1 in thread
Hi,
I've been reading "C++ GUI programming with QT4" and have stumbled upon a
small problem. For some strange reason, QFtp does not want to do _anything_.
I looked at one of the examples of how to write a commandline ftp-client. So,
I wrote almost exactly the same thing as in the book, but still no go.
This is what I have:
==in file main.cpp==
#include <QCoreApplication>
#include <iostream>
#include <QObject>
#include "FtpGet.h"
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
FtpGet getter;
getter.getFile();
QObject::connect(&getter, SIGNAL(done()), &app, SLOT(quit()));
return app.exec();
}
==in file FtpGet.h==
#ifndef FTPGET_H
#define FTPGET_H
#include <QFtp>
class FtpGet : public QObject {
Q_OBJECT
public:
FtpGet(QObject *parent = 0);
bool getFile();
signals:
void done();
private slots:
void ftpDone(bool error);
private:
QFtp ftp;
};
#endif
==in file FtpGet.cpp==
#include "FtpGet.h"
#include <iostream>
using namespace std;
FtpGet::FtpGet(QObject *parent) : QObject(parent) {
QObject::connect(&ftp, SIGNAL(done(bool)), this, SLOT(ftpDone(bool)));
}
bool FtpGet::getFile() {
ftp.connectToHost("ftp.trolltech.com"); // id == 1
ftp.login(); // id == 2
ftp.cd("qt"); // id == 3
ftp.get("INSTALL"); // id == 4
ftp.close(); // id == 5
return true;
}
void FtpGet::ftpDone(bool error) {
if(error) { cout << "error in transfer" << endl; }
cout << ftp.errorString().toStdString();
emit done();
}
Output when I run it is nothing.
I know that the event-queue has tp be running to get ftp-commands to work, so
I guess I have to run app.exec() before I try to do anything related to ftp,
BUT if I do that the program will just hang there and never reach the code
below.
Can anyone tell me what I can do here? Any help would be appreciated. I have
tried reading doc's and all, but have not discovered what my mistake here
is. :(
--
[ signature omitted ]
Message 2 in thread
Hi,
> I've been reading "C++ GUI programming with QT4" and have stumbled upon a
> small problem. For some strange reason, QFtp does not want to do _anything_.
>
> I looked at one of the examples of how to write a commandline ftp-client. So,
> I wrote almost exactly the same thing as in the book, but still no go.
I expect the example from the book to be working properly. Could you
describe th differences between your program and the example in the book?
My suggestion would be to start from the example in the book and modify
it until it doesn't work anymore.
There's also an example in:
examples/network/ftp
--
[ signature omitted ]
Message 3 in thread
Hi,
Thanks for such a swift reply Dimitri.
Tirsdag 13. mars 2007, skrev Dimitri:
> Hi,
>
> > I've been reading "C++ GUI programming with QT4" and have stumbled upon a
> > small problem. For some strange reason, QFtp does not want to do
> > _anything_.
> >
> > I looked at one of the examples of how to write a commandline ftp-client.
> > So, I wrote almost exactly the same thing as in the book, but still no
> > go.
>
> I expect the example from the book to be working properly. Could you
> describe th differences between your program and the example in the book?
The only difference is that I have removed some cout's from the
getFile-method. All they did was test for validUrl() and such.
> My suggestion would be to start from the example in the book and modify
> it until it doesn't work anymore.
>
> There's also an example in:
> examples/network/ftp
>
> --
> Dimitri
--
[ signature omitted ]