QFtpを使用してテキストファイルをFTPサーバーにアップロードしたいと考えています。Qt C++でファイルをアップロードするにはどうすればQFtp :: putを使用できますか?
これは私が持っているコードです:
QFile *file = new QFile("test.txt");
QFtp *ftp = new QFtp();
if(file->open(QIODevice::ReadWrite)) {
ftp->setTransferMode(QFtp::Active);
ftp->connectToHost(server);
ftp->login(name, password);
ftp->put(file, "test.txt");
ftp->close();
}
このコードを実行した後、私は私のftpサーバには何も表示されません。 QFtp :: putのドキュメントを見ると、最初のパラメータはQIODeviceまたはQByteArrayでなければなりません。私はこれをどのようにするべきですか?
編集:
だから私は今、このコードを持っている:これらの機能を持つ
//ftp.cpp
QFile *file = new QFile("test.txt");
QFtp *ftp = new QFtp();
this->connect(ftp, SIGNAL(commandStarted(int)), SLOT(ftpCommandStarted(int)));
this->connect(ftp, SIGNAL(commandFinished(int, bool)), SLOT(ftpCommandFinished(int, bool)));
this->connect(ftp, SIGNAL(done(bool)), SLOT(ftpDone(bool)));
this->connect(ftp, SIGNAL(dataTransferProgress(qint64, qint64)), SLOT(ftpDataTransferProgress(qint64, qint64)));
this->connect(ftp, SIGNAL(stateChanged(int)), SLOT(ftpStateChanged(int)));
if(file->open(QIODevice::ReadWrite)) {
ftp->setTransferMode(QFtp::Active);
ftp->connectToHost(server);
ftp->login(name, password);
ftp->put(file, "test.txt");
ftp->close();
}
を:
//ftp.h
void ftpCommandStarted(int id);
void ftpCommandFinished(int id, bool error);
void ftpDone(bool);
void ftpDataTransferProgress(qint64, qint64);
void ftpStateChanged(int);
//ftp.cpp
void EmailDialog::ftpCommandStarted(int id) {
this->messageBox("Command Started: " + QString::number(id));
}
void EmailDialog::ftpCommandFinished(int id, bool error) {
this->messageBox("Command Finished: " + QString::number(id) + " Error: " + (error ? "Error" : "No Error"));
}
void EmailDialog::ftpDone(bool error) {
this->messageBox("Done " + QString(error ? "Error" : "No Error"));
}
void EmailDialog::ftpDataTransferProgress(qint64 done, qint64 total) {
this->messageBox("Done: " + QString::number(done) + " Total: " + QString::number(total));
}
void EmailDialog::ftpStateChanged(int state) {
QString text;
switch (state) {
case 0:
text = "QFtp::Unconnected";
break;
case 1:
text = "QFtp::HostLookup";
break;
case 2:
text = "QFtp::Connecting";
break;
case 3:
text = "QFtp::Connected";
break;
case 4:
text = "QFtp::LoggingIn";
break;
case 5:
text = "QFtp::Closing";
break;
default:
text = "";
break;
}
this->messageBox(text);
}
しかし、私はスロットが呼び出されているという兆候を得ることはありません。私はメッセージボックスが現れない。私はここで間違って何をしていますか?
今はるかに良くなっていますが、間違ったことを言うにはあまりにも多くのコードがありません。それをgithubやbitbucketにすべてアップロードできますか? –
それはしばらくして、答えを選ぶことを検討するかもしれません... –
@RickSmithこれらのどれも働かなかった。私はやっとこれをあきらめ、何かをしました。 –