Results 1 to 3 of 3

Thread: save contents QTextEdit in a .txt file

  1. #1
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default save contents QTextEdit in a .txt file

    I found an example of this type:
    Qt Code:
    1. QString nomeFile = QFileDialog::getSaveFileName(this, tr("Salva il File"), "",
    2. tr("File di Testo (*.txt);;C++ File (*.cpp *.h)"));
    3. if (nomeFile != "") {
    4. QFile file(nomeFile);
    5.  
    6. if (file.open(QIODevice::ReadWrite)) {
    7. ---> QTextStream stream(&file); <-----
    8. stream << ui->editaTesto->toPlainText();
    9. file.flush();
    10. file.close();
    11. }
    12. else {
    13. QMessageBox::critical(this, tr("Errore"), tr("Non posso salvare il file"));
    14. return;
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 
    When I compile I get this error message referring to the line of code with the arrows:
    Qt Code:
    1. C:\Qt\progetti\test-MainWindow\notepad.cpp:46: error: variable 'QTextStream stream' has initializer but incomplete type
    To copy to clipboard, switch view to plain text mode 
    How should I write?

    Thanks to all

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: save contents QTextEdit in a .txt file

    You forgot:

    Qt Code:
    1. #include <QTextStream>
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: save contents QTextEdit in a .txt file

    Thank you very much

Similar Threads

  1. How to read changing file contents
    By tomkonikkara in forum Qt Programming
    Replies: 4
    Last Post: 10th July 2011, 19:11
  2. QTextEdit contents changed highlight the color
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 3
    Last Post: 8th June 2011, 17:31
  3. QTextEdit save as RichText width Images
    By kea_ in forum Qt Programming
    Replies: 2
    Last Post: 9th August 2010, 07:53
  4. Display contents of .txt file
    By karmo in forum Newbie
    Replies: 17
    Last Post: 23rd January 2010, 20:39

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.