Important: Please read the Qt Code of Conduct -

File saving without opening explorer

  • in notepad when i am triggering save it opens file explorer
    how to save in notepad without openning explorer
    i used this code
    void Diary::on_actionSave_triggered()
    QString fileName;

    if (currentFile.isEmpty()) {
        fileName = QFileDialog::getSaveFileName(this, "Save");
        currentFile = fileName;
    } else {
        fileName = currentFile;
    QFile file(fileName);
    if (! | QFile::Text)) {
        QMessageBox::warning(this, "Warning", "Cannot save file: " + file.errorString());
    QTextStream out(&file);
    QString text = ui->textEdit_diary->toPlainText();
    out << text;


  • Lifetime Qt Champion


    And what would your question be ?

  • @SGaist here when i am triggering save it open file explorer i don't want that.How can i set a directory of my choice?where in this code should i change?

  • @Mahin-Abid
    If you don't want a file-explorer-type interface to be shown to the user, don't call QFileDialog::getSaveFileName(). Its sole purpose is to prompt the user to choose.

    If you want to affect the initial directory of QFileDialog::getSaveFileName(), see and use the optional const QString &dir = QString() parameter.

    If you know what directory you want to save in and only want a filename from the user, use a plain QLineEdit for that.

Log in to reply