why the qftp failed in qmainwindow?where is its signal?
I use qftp to upload a test file in qmainwindow,but failed,Even i cannot pick up the signal,I think the code is right,why?
Code:
////////////////cfrmmain.h
class frmMainWindow
:public QMainWindow,
public Ui
::MainWindow {
Q_OBJECT
public:
frmMainWindow();
private:
private slots:
void btnStartClicked();
void ftpListInfo
(const QUrlInfo &urlInfo
);
void ftpCommandFinished(int commandId, bool error);
void updateDataTransferProgress(qint64 readBytes,qint64 totalBytes);
};
/////////////////cfrmmain.cpp/////////
frmMainWindow::frmMainWindow()
{
setupUi(this);
connect(startSCP,SIGNAL(clicked()),this ,SLOT(btnStartClicked()));
ftp=0;
}
void frmMainWindow::btnStartClicked()
{
if (ftp) {
ftp->abort();
ftp->deleteLater();
ftp = 0;
return;
}
connect(ftp, SIGNAL(commandFinished(int, bool)),
this, SLOT(ftpCommandFinished(int, bool)));
connect(ftp,
SIGNAL(listInfo
(const QUrlInfo &)),
this,
SLOT(ftpListInfo
(const QUrlInfo &)));
connect(ftp, SIGNAL(dataTransferProgress(qint64, qint64)),
this, SLOT(updateDataTransferProgress(qint64, qint64)));
ftp->connectToHost("ftp.trolltech.com");
ftp->login();
ftp->list();
}
[COLOR="Red"]/////////////////all the SLOT function cannot performed ,why????????[/COLOR]
void frmMainWindow::ftpCommandFinished(int, bool error)
{
if (ftp
->currentCommand
() == QFtp::ConnectToHost) { if (error) {
tr("Unable to connect to the FTP server "
"at %1. Please check that the host "
"name is correct.")
.arg("192.168.1.3"));
return;
}
return;
}
if (ftp
->currentCommand
() == QFtp::Get) {
}
if (ftp
->currentCommand
() == QFtp::List) {
}
if (ftp
->currentCommand
() == QFtp::Put) {
}
}
void frmMainWindow::updateDataTransferProgress(qint64 readBytes,
qint64 totalBytes)
{
void frmMainWindow
::ftpListInfo(const QUrlInfo &urlInfo
) {
fileList<<urlInfo.name() ;
}
Re: why the qftp failed in qmainwindow?where is its signal?
Because your slots are all private.
You use private slots only if signals from the same class are connected to them. Otherwise use protected or public slots.
Re: why the qftp failed in qmainwindow?where is its signal?
no,it's maybe not right.In the demo of QT examples\FTP, its slot is private and it works well. I rewrite the code and moved the private slot to public slot. it's just the same ,not work.:confused:
Re: why the qftp failed in qmainwindow?where is its signal?
Does it execute the btnStartClicked slot when you click the button?
Also, check the console, often Qt leaves some messages when something goes wrong.
If btnStartClicked is not called, then you ftp object is not created.
Re: why the qftp failed in qmainwindow?where is its signal?
yes,it executed.But the console reports nothing!
Re: why the qftp failed in qmainwindow?where is its signal?
Well, the only difference between your code and the ftp example is that the ftp object is created with a parent (this ). But I do not believe this is the reason.= your slots don't get called.
Can you post your moc_cfrmain.cpp? We can see there if the signals are mapped correctly.
Re: why the qftp failed in qmainwindow?where is its signal?
Quote:
Originally Posted by
marcel
You use private slots only if signals from the same class are connected to them.
There's nothing wrong in connecting non-local signals to private slots.
Quote:
Originally Posted by
cxl2253
yes,it executed.But the console reports nothing!
Make sure your application is compiled in debug mode (on windows you will also have to add CONFIG += console to your .pro file).
Also check whether all connect() statements return true.
Re: why the qftp failed in qmainwindow?where is its signal?
yes,my compiler flag is MDD. But i donot understand what's wrong with the code.I even want to give up qt, why there are so many problem?:D
Re: why the qftp failed in qmainwindow?where is its signal?
I just tested your code and it works.
The header:
Code:
#ifndef FTP3_H
#define FTP3_H
#include <QtGui/QMainWindow>
#include "ui_ftp3.h"
#include <QUrlInfo>
{
Q_OBJECT
public:
ftp3
(QWidget *parent
= 0, Qt
::WFlags flags
= 0);
~ftp3();
private:
Ui::ftp3Class ui;
private slots:
void ftpListInfo
(const QUrlInfo &urlInfo
);
void ftpCommandFinished(int commandId, bool error);
void updateDataTransferProgress(qint64 readBytes,qint64 totalBytes);
};
#endif // FTP3_H
The cpp:
Code:
#include "ftp3.h"
#include <QFtp>
#include <QMessageBox>
ftp3
::ftp3(QWidget *parent, Qt
::WFlags flags
){
ui.setupUi(this);
ftp = 0;
file = 0;
if (ftp)
{
ftp->abort();
ftp->deleteLater();
ftp = 0;
return;
}
connect(ftp, SIGNAL(commandFinished(int, bool)),
this, SLOT(ftpCommandFinished(int, bool)));
connect(ftp,
SIGNAL(listInfo
(const QUrlInfo &)),
this,
SLOT(ftpListInfo
(const QUrlInfo &)));
connect(ftp, SIGNAL(dataTransferProgress(qint64, qint64)),
this, SLOT(updateDataTransferProgress(qint64, qint64)));
ftp->connectToHost("ftp.trolltech.com");
ftp->login();
ftp->list();
}
ftp3::~ftp3()
{
}
void ftp3::ftpCommandFinished(int, bool error)
{
if (ftp
->currentCommand
() == QFtp::ConnectToHost) { if (error) {
tr("Unable to connect to the FTP server "
"at %1. Please check that the host "
"name is correct.")
.arg("192.168.1.3"));
return;
}
return;
}
if (ftp
->currentCommand
() == QFtp::Get) {
}
if (ftp
->currentCommand
() == QFtp::List) {
}
if (ftp
->currentCommand
() == QFtp::Put) {
}
}
void ftp3::updateDataTransferProgress(qint64 readBytes, qint64 totalBytes)
{
}
void ftp3
::ftpListInfo(const QUrlInfo &urlInfo
) {
fileList<<urlInfo.name() ;
}
The only difference is that I didn't use the button. I create the ftp client in the constructor of the main window.
Could you test this? Do you get the same result?
regards
Re: why the qftp failed in qmainwindow?where is its signal?
there are still problem! I used qt422 open source and vc2003.I found when i compiled its example in ..\examples\network\ftp in vc enviroment, not used qmake, the exe cannot emit the signal and not even to connect to ftp server. but when used qmake ,all is right. why??
Re: why the qftp failed in qmainwindow?where is its signal?
Can anybody send me a project about qftp demo in vc ?thanks. my email is cxl2253@gmail.com
1 Attachment(s)
Re: why the qftp failed in qmainwindow?where is its signal?
Try this one... It's the example I attached. It worked with 4.2.2 and VS 2003.
Regards
Re: why the qftp failed in qmainwindow?where is its signal?
Hey, are you sure you don't have a firewall on or anything else that could block the ftp client? Or have you waited enough? Last time I tested the requestFinished response came a little late ( about 10 seconds )?
Regards
Re: why the qftp failed in qmainwindow?where is its signal?
thanks,I will test your provided demo. I used the exe compiled by vc and the other compiled by qmake. The first one cannot response, the other can .
1 Attachment(s)
Re: why the qftp failed in qmainwindow?where is its signal?
your code can work well, thanks , but i am surprised that why my code from the QT demo cannot emit the signal? can you help me ? All the code is from QT demo ,I only created a vc project files.
attached file :
Attachment 1106
Re: why the qftp failed in qmainwindow?where is its signal?
marcel,I have made a lower mistake, I used the QtNetwork4.lib, not the QtNetworkd4.lib in debug mode .Thaks for your help again.