Pergunta

I just wrote tiny ftp client using Qt. The problem is when I download, the ftp->get() command downloads the file to the default location. I'd like to define a path where the downloaded file will go.

This is my DownloadFile method:

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);
Foi útil?

Solução

Just create the file object with the path you want and QFtp will save there. Something like;

file = new QFile(QString("/path/to/download/%1").arg(fileName));
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top