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. Saving data from form to txt file

Saving data from form to txt file

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.9k 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.
  • H Offline
    H Offline
    hogen
    wrote on last edited by
    #1

    Hello,
    I have a problem with saving data from lineEdit end etc. to txt File.

    @void MainWindow::on_pushButton_2_clicked()
    {
    QString fileName = QFileDialog::getSaveFileName(this, tr("Zapisz plik"), "",
    tr("Plik tekstowy (.txt);;Plik C++ (.cpp *.h)"));

     if (fileName != "") {
         QFile file(fileName);
         if (!file.open(QFile::WriteOnly | QFile::Text)) {
             // error
         } else {
             QTextStream stream(&file);
             stream.setIntegerBase(10);
             stream << "Czas: " << timeEdit->time().toString() << "\n\n";
             stream << "Data: " << dateEdit->date().toString() << "\n\n";
             stream << "Miejsce: " << lineEdit->text() << "\n\n";
             stream << "Temat: " << lineEdit_2->text() << "\n\n";
             //stream << "Wiadomosc: " << textEdit-> << "\n\n";
             stream.flush();
             file.close();
         }
     }
    

    }@

    Content of .txt file:


    Czas:

    Data: 0x4

    Miejsce: 0x22fe48

    Temat: 0x40bab2

    Wiadomosc: 0x0


    What is wrong ?
    Greetings !

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      What happens when you use QFile::write() instead of a stream?

      (Z(:^

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hogen
        wrote on last edited by
        #3

        Error:

        'Write' is not a member of 'QFile'

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          "It is.":http://qt-project.org/doc/qt-5.0/qtcore/qiodevice.html#write-3

          (Z(:^

          1 Reply Last reply
          0
          • raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            the code of your first post works fine for me.
            Try adding the following line:
            @
            stream.setCodec("UTF-8");
            @

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0

            • Login

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