Unsolved 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 (!file.open(QIODevice::WriteOnly | QFile::Text)) { QMessageBox::warning(this, "Warning", "Cannot save file: " + file.errorString()); return; } setWindowTitle(fileName); QTextStream out(&file); QString text = ui->textEdit_diary->toPlainText(); out << text; file.close();
}
-
Hi,
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 callQFileDialog::getSaveFileName()
. Its sole purpose is to prompt the user to choose.If you want to affect the initial directory of
QFileDialog::getSaveFileName()
, see https://doc.qt.io/qt-5/qfiledialog.html#getSaveFileName and use the optionalconst 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.