QFtp...doesnt seems to work ....!!!
hey guys....i have written this piece of code for a QFtp application,but this doesnt seem to work....i dont know whr it goes wrong,but it makes a file with 0 byte.......pls,pls any help wud be appreciated....
Code:
/* main method */
#include <QtGui/QApplication>
#include <QApplication>
#include "exftp.h"
int main(int argc, char *argv[])
{
exFtp w;
w.show();
//a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
return a.exec();
}
Code:
/* .h File */
#ifndef EXFTP_H
#define EXFTP_H
#include <QtGui/QMainWindow>
#include <QFtp>
#include <QUrl>
#include <QFile>
#include <QDialog>
#include <QString>
//#include "ui_exftp.h"
{
Q_OBJECT
public:
exFtp();
~exFtp();
private:
//Ui::exFtpClass ui;
private slots:
bool downloadStarted();
void EnabledButton(const QString&);
void ftpDone(bool);
void On_CommandFinished();
};
#endif // EXFTP_H
Code:
/* .cpp file */
#include <QtGui>
#include "exftp.h"
exFtp::exFtp()
{
ftpServerLabel
= new QLabel("FTP");
downloadButton->setEnabled(false);
topLayout->addWidget(ftpServerLabel);
topLayout->addWidget(ftpServerLineEdit);
mainLayout->addLayout(topLayout);
mainLayout->addWidget(statusLabel);
mainLayout->addWidget(buttonBox);
setLayout(mainLayout);
connect(ftpServerLineEdit,SIGNAL(textEdited(const QString&)),this,SLOT(EnabledButton(const QString&)));
// connect(ftpServerLineEdit,SIGNAL(textEdited(const QString&)),this,SLOT(QUrl(const QString&)))
connect(downloadButton,SIGNAL(clicked()),this,SLOT(downloadStarted()));
connect(ftp,SIGNAL(done(bool)),this,SLOT(ftpDone(bool)));
connect(ftp,SIGNAL(commandFinished(int,bool)),this,SLOT(On_CommandFinished()));
connect(quitButton,SIGNAL(clicked()),this,SLOT(accept()));
//ui.setupUi(this);
}
void exFtp::EnabledButton(const QString& Url)
{
downloadButton->setEnabled(!(Url.isEmpty()));
urlAdd->setUrl(Url);
urlAdd->setPath(Url);
localFileName = fi.fileName();
if(localFileName.isEmpty())
localFileName = "exFtp.out";
}
void exFtp::On_CommandFinished()
{
file.close();
}
bool exFtp::downloadStarted()
{
file.setFileName(localFileName);
//file.open(QIODevice::WriteOnly);
{
statusLabel->setEnabled(true);
statusLabel->setText(tr("File at %1 cannot be Open/Accesed").arg(localFileName));
return false;
}
ftp->connectToHost(urlAdd->host(),urlAdd->port(21));
ftp->login();
ftp->get(urlAdd->path(),&file);
//ftp->close();
return true;
}
void exFtp::ftpDone(bool fileDone)
{
if(fileDone)
statusLabel->setText("DownLoaded");
else
statusLabel->setText("no,..!!");
}
exFtp::~exFtp()
{
}
Re: QFtp...doesnt seems to work ....!!!
Well, I'm relatively new to Qt, but did you check the FTP example? :confused:
Re: QFtp...doesnt seems to work ....!!!
yup...i have seen the example....nd taken all possible clues from it....but no use....still the prob. is there......
Re: QFtp...doesnt seems to work ....!!!
Either monitor the network traffic or the state of the QFtp object and see at which point the execution stops - see if the component connects to the host, logins, etc. At some point it probably fails to do its task but you don't notice it.
Re: QFtp...doesnt seems to work ....!!!
yup,u r rite,the execution is not proper ....but i think thr is problem in code,m nt sure if QFtp is used properly in the code....
i cannt undestand what u mean by monitoring traffic..?...nd can u tell me a reliable site....which if provided downloads a file from it...
Re: QFtp...doesnt seems to work ....!!!
Quote:
Originally Posted by
salmanmanekia
yup,u r rite,the execution is not proper ....but i think thr is problem in code,m nt sure if QFtp is used properly in the code....
Please use proper sentences instead of that awful sms slang.
Quote:
i cannt undestand what u mean by monitoring traffic..?
I mean see what goes through your network interface card. There are many networking sniffer tools that do this - just search the net.
Re: QFtp...doesnt seems to work ....!!!
Thanks for the advice...
I am not sure about network sniffer,is it realy necessary and dont you see any problem with the code....what i understand is that if code is fine then it should work and vice versa....aint it...!!
Re: QFtp...doesnt seems to work ....!!!
Quote:
Originally Posted by
salmanmanekia
I am not sure about network sniffer,is it realy necessary
No, it's not necessary - you can go for the other approach I suggested. But the sniffer will show you what exactly happens during the connection (and if there is a connection at all). To monitor the state of the object you'll need to write some debugging code and deduce the problem from received output.
Quote:
dont you see any problem with the code...
I don't see anything obvious.
Quote:
what i understand is that if code is fine then it should work and vice versa
Then you understand incorrectly. The code might be fine but for example your personal firewall might be blocking the connection.
Re: QFtp...doesnt seems to work ....!!!
Worked the Program with Network sniffer,it doesnt detect any Incoming /Outgoing FTP packets,but the firewall i have installed asks me for the connection to be established when i run the program.....the firewall is of panda.....just for the sake of confirmation the address which i provide in FTP address bar is "ftp.trolltech.com"....is this right...??
Re: QFtp...doesnt seems to work ....!!!
Quote:
Originally Posted by
salmanmanekia
Worked the Program with Network sniffer,it doesnt detect any Incoming /Outgoing FTP packets
How about any packets going to ftp.trolltech.com? Can you connect to ftp.trolltech.com using your regular ftp client? Does the sniffer report the traffic on ftp ports then?
Re: QFtp...doesnt seems to work ....!!!
Quote:
Can you connect to ftp.trolltech.com using your regular ftp client?
Yup,the ftp address works fine.