If you look at every overloaded output operator, you will see that none have a const
qualifier. Which is your problem, you try to modify a constant object. Remove the const
qualification of the qDebugObject
and the return value.
You should have compiler warnings screaming about it, and if not then you need to enable more warnings (at least use -Wall
when compiling with GCC/clang).
The actual problem, as answered by Mike Seymour in a comment, is that your overload will be called recursively until you get a stack overflow.
A way of bypassing that might be to convert the string to something else, like for example a QString
:
return qDebugObj << QString::fromStdString(str);