我刚刚使用QT编写了Tiny FTP客户端。问题是当我下载时 ftp->get() 命令将文件下载到默认位置。我想定义下载文件将进入的路径。

这是我的 DownloadFile 方法:

QString fileName = fileListTreeWidget->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(fileListTreeWidget->currentItem()->text(0), file);
有帮助吗?

解决方案

只需创建 file 对象带有您想要的路径和 QFtp 会保存在那里。就像是;

file = new QFile(QString("/path/to/download/%1").arg(fileName));
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top