PDA

View Full Version : Error printing a string



ayanda83
11th July 2012, 08:03
Hi there, why does the following statement give an error in Qt?
cout << r1.toString() <<endl; 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.
7994
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.

wysota
11th July 2012, 08:07
What is the signature of R::toString()? Does QTextStream know how to handle it?

ayanda83
11th July 2012, 14:45
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.

high_flyer
11th July 2012, 14:57
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/qstring.html#toStdString