Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. File saving without opening explorer
Forum Updated to NodeBB v4.3 + New Features

File saving without opening explorer

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 368 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Mahin AbidM Offline
    Mahin AbidM Offline
    Mahin Abid
    wrote on last edited by aha_1980
    #1

    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();
    

    }

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      And what would your question be ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Mahin AbidM 1 Reply Last reply
      2
      • SGaistS SGaist

        Hi,

        And what would your question be ?

        Mahin AbidM Offline
        Mahin AbidM Offline
        Mahin Abid
        wrote on last edited by Mahin Abid
        #3

        @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?

        JonBJ 1 Reply Last reply
        0
        • Mahin AbidM Mahin Abid

          @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?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @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 https://doc.qt.io/qt-5/qfiledialog.html#getSaveFileName 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.

          1 Reply Last reply
          3

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved