Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/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\\"))
    
        {
            dir.mkpath("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;
        dialog.setSidebarUrls(urls);
        QFileDialog::getSaveFileName(&dialog,tr("Copia File"), path_file, tr("(*.txt)"), nullptr, QFileDialog::DontUseNativeDialog);
        dialog.exec();
    

    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

    Hi
    QFileDialog::getSaveFileName
    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

    @vale88

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


Log in to reply