[SOLVED] qDebug() << syntax not working on Windows in QT5
In the" QGlobal documentation":http://qt-project.org/doc/qt-5.0/qtcore/qtglobal.html#qWarning, it says if you'd like to use the qDebug() << "blah" syntax, to #include <QtDebug>.
My understanding is that when you do qDebug() or qWarning() with no arguments, that a QDebug object is returned which is a stream-like object. Ok, that makes sense.
I did #include <QtDebug> successfully in a project on Mac OSX and used qDebug() << "blah", although very strangely it would only work if it were at the top of the .cpp in which I actually used the qDebug(); I could not put the include a global header or 'lower than other headers' even in the same .cpp file.
So, anyway, with this code that frailly works on a Mac OSX, I then try to compile it on Windows...
In this case, I get a compiler error, 'QMessageLogger::debug' does not take 0 arguments. I have tried a few things haphazardly without success to make it work.
I've tried to figure out what #include <QtDebug> is trying to do; so far, unsuccessfully. QtDebug just includes qdebug.h, which I've scanned, and nothing in that header is obvious to me in explaining how qDebug(), qWarning(), qCritical(), etc are set up to return a QDebug object when invoked with no arguments.
If you look in qlogging.h, I think the answer is in there. I can see this code:
QDebug debug() const;
QDebug warning() const;
QDebug critical() const;
QNoDebug noDebug() const Q_DECL_NOTHROW;
#endif // QT_NO_DEBUG_STREAM
It must be that I have the symbol QT_NO_DEBUG_STREAM defined somehow or another... I'll investigate that angle.
grep will be your friend for source files. If you are using QtCreator you might want to check the Build Settings in the project panel
I am using
qDebug() << "blabla";
on windows with Qt5 successfully.
I started with qDebug() and redirecting information with Qt4.7 or Qt4.8. I did not notice any particular difference for qDebug() when "migrating" to Qt5.1.
Qt4.7 was precompilation for msvc. Qt4.8 is self-compiled with MinGW 4.6 32 bit and MinGW 4.7 64 bit, while Qt5.1 I am using the MinGW prebuild as to be downloaded from here.
IIRC I had to add a couple of includes in addition in source files, which where found before in the depth of other includes before. However, this is nothing I have bothered to study in detail and reflects more a gut feeling than a sound proof.
I did find something; someone had defined
in the QT4.8 version of our project. So that's the problem. But I don't think the story ends there.
Because qWarning() <<"" worked in qt4.8 regardless of that flag (at least, it did for me), I believe it was not their intention to cause this to no longer work.
I see that QT_NO_DEBUG_STREAM is used throughout QT code to decide whether to support the << operator with a QDebug object; I suspect that whomever added QT_NO_DEBUG_STREAM was trying to suppress this particular functionality. (i'm about to go dig through the git logs and found out, and ask them)
After going through this, I'm of the opinion that this flag should not govern both 'can an Object be << to a QDebug object' and 'should qWarning() return a QDebug object'. But the flag rules both so there you are: )
Thanks for the pointers.