Results 1 to 4 of 4

Thread: Error printing a string

  1. #1
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Smile Error printing a string

    Hi there, why does the following statement give an error in Qt?
    Qt Code:
    1. cout << r1.toString() <<endl;
    To copy to clipboard, switch view to plain text mode 
    I have a class named "R" and r1 is an object of class "R". toString() is a string returning member function of class "R". when I run my program I get the following error.
    errorImage.jpg
    I have to mention that the above does not give an error when run in pure C++. It's only when I run it in Qt that it gives an error.
    Last edited by ayanda83; 11th July 2012 at 08:21.

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

    Default Re: Error printing a string

    What is the signature of R::toString()? Does QTextStream know how to handle it?
    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
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Error printing a string

    I'm kind of new to Qt, I have no clue how to do that. In C++ I would have just overloaded the insertion operator and the problem would have been solved. so please show me how to do this one, if you don't mind.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Error printing a string

    Qt is a collection nof C++ classes.
    Everything you can do with STL you can do with Qt too.
    Nothing hinders you from overloading the insertion operation or the global operator.

    QString has also an STL version string method:
    http://qt-project.org/doc/qt-4.8/qst...ml#toStdString
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. std string to QString error
    By Daxos in forum Qt Programming
    Replies: 2
    Last Post: 24th May 2010, 16:38
  2. std:string how to change into system:string?
    By yunpeng880 in forum Qt Programming
    Replies: 1
    Last Post: 14th April 2009, 08:51
  3. String operations, printing to stdout
    By Cruz in forum Newbie
    Replies: 3
    Last Post: 20th January 2009, 15:30
  4. Int to String - manipulating string
    By mickey in forum General Programming
    Replies: 6
    Last Post: 5th November 2007, 20:11

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.