Results 1 to 5 of 5

Thread: QTextStream object

  1. #1
    Join Date
    Oct 2009
    Location
    South Africa
    Posts
    94
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default QTextStream object

    I am trying to use a QTextStream object as a data member as follows:

    [in .h file]
    Qt Code:
    1. private:
    To copy to clipboard, switch view to plain text mode 
    [in .cpp file]
    Qt Code:
    1. QFile file(fileName);
    2. if (!file.open(QIODevice::Append | QIODevice::Text))
    3. return;
    4.  
    5. out = new QTextStream(&file);
    6. out << "test";
    To copy to clipboard, switch view to plain text mode 
    ...

    but it has a compile time error
    error: invalid operands of types `QTextStream*' and `const char[5]' to binary `operator<<'

    I then modified it to

    Qt Code:
    1. QTextStream o(&file);
    2. out = &o;
    3. out << "test";
    To copy to clipboard, switch view to plain text mode 
    but still the same error.
    Can someone please tell me the correct way to do this?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: QTextStream object

    You have to use
    Qt Code:
    1. *out << "test";
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Oct 2009
    Location
    South Africa
    Posts
    94
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: QTextStream object

    That was [very] quick.
    Thanks.

    But can you then tell me why? It seems different to how other objects get declared and used?

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: QTextStream object

    if you use
    Qt Code:
    1. out << "foo";
    To copy to clipboard, switch view to plain text mode 
    out is treated as a normal "plain" pointer (without any knowledge of QTextStrem) and operator << is applied for that. Only ofter dereference you can use the operator.

  5. #5
    Join Date
    Oct 2009
    Location
    South Africa
    Posts
    94
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: QTextStream object

    I understand, thanks for that.

Similar Threads

  1. Eclipse debugging: Unable to create variable object
    By PUK_999 in forum Installation and Deployment
    Replies: 0
    Last Post: 20th August 2009, 22:42
  2. Replies: 4
    Last Post: 19th February 2009, 12:10
  3. Help with Q_PROPERTY with object pointer
    By lni in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2009, 18:31
  4. QTextStream setup for networking?
    By invictus in forum Newbie
    Replies: 5
    Last Post: 24th February 2008, 01:23
  5. Create QTextStream
    By Morea in forum Qt Programming
    Replies: 1
    Last Post: 17th June 2007, 21:25

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
  •  
Qt is a trademark of The Qt Company.