Redirect Qt messages to sqlite log mechanism

In Windows (related issue #1069) and maybe in macOS (related issue #1982)
output to console is inhibited.

This will allow these messages to be seen in our Error Log window.
This commit is contained in:
mgrojo
2020-08-17 20:40:04 +02:00
parent 54ee47b5a9
commit 55637c284f

View File

@@ -1,7 +1,23 @@
#include "Application.h"
#include "sqlite.h"
void db4sMessageOutput(QtMsgType type, const QMessageLogContext &, const QString &msg)
{
QByteArray localMsg = msg.toLocal8Bit();
// Emulate the default Qt treatment. This might not work in some OS, like Windows.
fprintf(stderr, "%s\n", localMsg.constData());
// Log using the SQLite log mechanism, so it gets the same treatment than messages
// reported by SQLite itself. This will allow these messages to be seen in our Log window.
// Error code will be the type
sqlite3_log(static_cast<int>(type), "%s\n", localMsg.constData());
}
int main( int argc, char ** argv )
{
qInstallMessageHandler(db4sMessageOutput);
// Create application object. All the initialisation stuff happens in there
Application a(argc, argv);