How to overload operator<< for qDebug
Posted
by iyo
on Stack Overflow
See other posts from Stack Overflow
or by iyo
Published on 2010-04-20T18:17:50Z
Indexed on
2010/04/20
18:23 UTC
Read the original article
Hit count: 374
Hi,
I'm trying to create more useful debug messages for my class where store data. My code is looking something like this
#include <QAbstractTableModel>
#include <QDebug>
/**
* Model for storing data.
*/
class DataModel : public QAbstractTableModel {
// for debugging purposes
friend QDebug & operator<< (const QDebug &d, DataModel model);
//other stuff
};
/**
* Overloading operator for debugging purposes
*/
QDebug & operator<< (QDebug &d, DataModel model) {
d << "Hello world!";
return d;
}
I expect qDebug() << model
will print "Hello world!". However, there is alway something like "QAbstractTableModel(0x1c7e520)" on the output.
Do you have any idea what's wrong?
© Stack Overflow or respective owner