Results 1 to 4 of 4

Thread: reading QTextEdit from file

  1. #1
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default reading QTextEdit from file

    to write :
    Qt Code:
    1. QFile file( s_filename );
    2. if (file.open(QIODevice::WriteOnly))
    3. {
    4. QTextStream os(&file);
    5. os << qMessage->toPlainText() << endl;
    6. }
    To copy to clipboard, switch view to plain text mode 

    to read ?
    Qt Code:
    1. qMessage << is; // 226
    To copy to clipboard, switch view to plain text mode 

    compiler says :
    226 C:\Qt\test\sms\menu.cpp no match for 'operator<<' in '((ApplicationWindow*)this)->ApplicationWindow::qMessage << is'
    note C:\Qt\4.1.1\src\corelib\tools\qchar.h:291 candidates are: QDataStream& operator<<(QDataStream&, const QChar&) etc...

    How can I read in one step as I wrote to the file ?

    NB idem if I use to QString as for >>
    Last edited by incapacitant; 29th March 2006 at 21:15.

  2. #2
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: reading QTextEdit from file

    Qt Code:
    1. qMessage.setPlainText( is.readAll() )
    To copy to clipboard, switch view to plain text mode 

    does that fit?
    Current Qt projects : QCodeEdit, RotiDeCode

  3. The following user says thank you to fullmetalcoder for this useful post:

    incapacitant (29th March 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: reading QTextEdit from file

    Qt Code:
    1. qMessage.setPlainText( is.readAll() );
    To copy to clipboard, switch view to plain text mode 

    compiler says
    226 C:\Qt\test\sms\menu.cpp `setPlainText' has not been declared

    even with include <QTextEdit> !

  5. #4
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: reading QTextEdit from file

    looks like your textedit is a pointer while your previous code assumed it was not ( << operator doesn't work with pointers...)

    try out "->" operator instead of "."
    Current Qt projects : QCodeEdit, RotiDeCode

  6. The following user says thank you to fullmetalcoder for this useful post:

    incapacitant (29th March 2006)

Similar Threads

  1. help in reading XML file
    By cshiva_in in forum Qt Programming
    Replies: 1
    Last Post: 24th March 2008, 13:55
  2. QTextStream loses position while reading file
    By bjh in forum Qt Programming
    Replies: 2
    Last Post: 13th February 2008, 15:47
  3. Replies: 3
    Last Post: 18th October 2007, 18:07
  4. QWT 5, QT3, SuSE 10.2. Crash and burn
    By DrMcCleod in forum Qwt
    Replies: 8
    Last Post: 7th September 2007, 20:53
  5. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21

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.