//////////////storethread.h/////////
class storescpThread
:public QThread{
Q_OBJECT
public:
~storescpThread();
private slots:
void connectOrDisconnect();
void ftpListInfo
(const QUrlInfo &urlInfo
);
void ftpCommandFinished(int commandId, bool error);
void updateDataTransferProgress(qint64 readBytes,qint64 totalBytes);
private :
}
/////////////////////////storethread.cxx//////////
{
ftp=0;
}
void storescpThread::connectOrDisconnect()
{
if (ftp) {
ftp->abort();
ftp->deleteLater();
ftp = 0;
}
//the SLOT function not be perfomed! why?
[FONT="Arial Black"]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)));[/FONT]
ftp->connectToHost("192.168.1.1");
ftp->login("ftpuser","ftpuser");
ftp->cd("/data"); //init dir
fileList.clear();
ftp->list();
QFile file("c:\\testdata.jpg");
return false;
ftp->put(&file,"testtest.jpg"); //the file not be uploaded!!!!!
}
// the following SLOT not be perfomed!where is the emited message?
void storescpThread::ftpCommandFinished(int, bool error)
{
if (ftp
->currentCommand
() == QFtp::ConnectToHost) { if (error) {
tr("error"));
return;
}
return;
}
if (ftp
->currentCommand
() == QFtp::Get) {
}
if (ftp
->currentCommand
() == QFtp::List) { }
if (ftp
->currentCommand
() == QFtp::Put) {
}
}
void storescpThread::updateDataTransferProgress(qint64 readBytes, qint64 totalBytes)
{
}
void storescpThread
::ftpListInfo(const QUrlInfo &urlInfo
) {
fileList<<urlInfo.name() ;
}
//////////////storethread.h/////////
class storescpThread:public QThread
{
Q_OBJECT
public:
storescpThread(QTextEdit *txtEdit,QObject *parent = 0);
~storescpThread();
private slots:
void connectOrDisconnect();
void ftpListInfo(const QUrlInfo &urlInfo);
void ftpCommandFinished(int commandId, bool error);
void updateDataTransferProgress(qint64 readBytes,qint64 totalBytes);
private :
QTextEdit * textEdit;
QFtp *ftp;
QFile *file;
QStringList fileList;
}
/////////////////////////storethread.cxx//////////
storescpThread::storescpThread(QTextEdit *txtEdit,QObject *parent): QThread(parent)
{
ftp=0;
}
void storescpThread::connectOrDisconnect()
{
if (ftp) {
ftp->abort();
ftp->deleteLater();
ftp = 0;
}
ftp = new QFtp(this);
//the SLOT function not be perfomed! why?
[FONT="Arial Black"]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)));[/FONT]
ftp->connectToHost("192.168.1.1");
ftp->login("ftpuser","ftpuser");
ftp->cd("/data"); //init dir
fileList.clear();
ftp->list();
QFile file("c:\\testdata.jpg");
if (!file.open(QIODevice::ReadOnly))
return false;
QFileInfo fi(filename);
ftp->put(&file,"testtest.jpg"); //the file not be uploaded!!!!!
}
// the following SLOT not be perfomed!where is the emited message?
void storescpThread::ftpCommandFinished(int, bool error)
{
if (ftp->currentCommand() == QFtp::ConnectToHost) {
if (error) {
QMessageBox::information(0, tr("FTP"),
tr("error"));
return;
}
return;
}
if (ftp->currentCommand() == QFtp::Get) {
}
if (ftp->currentCommand() == QFtp::List) {
QMessageBox::information(0, tr("FTP"),"LIST");
}
if (ftp->currentCommand() == QFtp::Put) {
}
}
void storescpThread::updateDataTransferProgress(qint64 readBytes, qint64 totalBytes)
{
}
void storescpThread::ftpListInfo(const QUrlInfo &urlInfo)
{
fileList<<urlInfo.name() ;
}
To copy to clipboard, switch view to plain text mode
Bookmarks