Important: Please read the Qt Code of Conduct -

QFile dialog to save a file

  • QString path_file = QString("%1\\%2\\%3").arg(ROOT_ACQUISITION,cartella,text_file_da_copiare );
        QString path_nuovo= QString("%1\\%2").arg("C:\\cartella\\",nome_file);
        QDir dir;
        if (!dir.exists("C:\\cartella\\"))
    //    if (QFile::exists(path_file))
    //        QFile::remove(path_nuovo);
        //QFile::copy(path_file, path_nuovo);
        QList<QUrl> urls;
        urls << QUrl::fromLocalFile("C://Acquisizione");
        QFileDialog dialog;
        QFileDialog::getSaveFileName(&dialog,tr("Copia File"), path_file, tr("(*.txt)"), nullptr, QFileDialog::DontUseNativeDialog);

    I have to save a file that I select but when I choice the path an other window opens and the file isn't saved

  • Lifetime Qt Champion

    only gets a filename/path so it will not save anything for you.
    so you need some code to save data.

  • @mrjj ok, so in this way I obtain the path that I choice to save?
    then I can use:

    QFile::copy(path_file, path_nuovo);

  • Lifetime Qt Champion


    Yes. if the file you select should be copied to path_nuovo

Log in to reply