qDebug Console output with Timestamp

You could install a message handler and print out the timestamp before every message. See the documentation of qInstallMessageHandler for this. With this solution you don't have to add QTimer::currentTime() on every call of qDebug().


Sure you can. For doing so you can use QTime class, i.e.:

qDebug() << QTime::currentTime().toString() << "YOU MESSED UP "<< db.lastError().text();

Or, in the same way you can print out the date and time information with using QDateTime::currentDateTime() function.


If you are on linux, you can set QT_MESSAGE_PATTERN environment variable,as explained here:

QT_MESSAGE_PATTERN="[%{type}] %{appname} (%{file}:%{line}) - %{message}"