QFiledialog : how to pass a file to qfiledialog for save as?

196 views Asked by At

I try to create "Save as..." dialog in Ubuntu. But I want to use it just for save as a file is there any way to pass file and its path to this dialog? this is my code:

   int main(int agc,char **argv){
     QApplication app(argc,argv);
     QFileDialog my;
     my.getSaveFileName(0."Save file ",QDir::currentPath,"Music files(*.mp3;;Text files (*.txt)"));
     my.selectFile("myfile.txt");
    return 0;
    }
1

There are 1 answers

0
Tarod On

You should pass the file name and its path in the second argument.

Example:

#include <QApplication>
#include <QFileDialog>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QString path = QDir::currentPath() + "/myfile.txt";

    QString fileName = QFileDialog::getSaveFileName(0, "Save file",
                                                    path,
                                                    "Music files(*.mp3;;Text files (*.txt)");

    return a.exec();
}