Qt4.3.0里面有个Example,NetWorking下的FTP Client,连接到服务器后下载文件到执行文件所在的目录下,现在我想把下载路径手动指定,就像Save as一样,怎么实现?
void FtpWindow::downloadFile()
{
QString fileName = fileList->currentItem()->text(0);
if (QFile::exists(fileName)) {
QMessageBox::information(this, tr("FTP"),
tr("There already exists a file called %1 in "
"the current directory.")
.arg(fileName));
return;
}
file = new QFile(fileName);
if (!file->open(QIODevice::WriteOnly)) {
QMessageBox::information(this, tr("FTP"),
tr("Unable to save the file %1: %2.")
.arg(fileName).arg(file->errorString()));
delete file;
return;
}
ftp->get(fileList->currentItem()->text(0), file);
progressDialog->setLabelText(tr("Downloading %1...").arg(fileName));
downloadButton->setEnabled(false);
progressDialog->exec();
}
我尝试学着Save as方法:
QString fileName1 = QFileDialog::getSaveFileName(this);
if (fileName1.isEmpty())
return ;
file = new QFile(fileName1);
但是这样的话,路径是可以选了,可是要手动填入保存文件的名称,而我想实现的是指定目录后,名称和FTP上的文件名是一样的。这个怎么实现呢?
希望高手帮我解决一下。
还有就是连接到服务器后所显示的中文名全是乱码的呢,网上的一些方法我都试过了,还是不行。