Skip to content

Add an runtime_error to `qcr::messageHandler` to make sure it lives inside the main thread

Christian Trageser requested to merge issue7 into main

This adds an assert to qcr::messageHandler which will fail when messageHandler lives outside the main thread

This is important since this custom message Handler utilizes QMessageBoxes to display messages graphically to the user. These QMessageBoxes (like all QWidgets) do not work outside the main thread. If they are used in such a way they will crash unpredictably, and it is very hard to find the cause.

This change make sure the developer will quickly find the reason for this crash.

steca: /home/trageser/dev/libqcr/QCR/services/msg_handler.cpp:39: void qcr::messageHandler(QtMsgType, const QMessageLogContext&, const QString&): Assertion `is_gui_thread && "qcr::messageHandler was called from a non GUI thread."' failed.
Aborted (core dumped)

Please keep in mind: qt message handler will handle qWarning() qDebug() etc .. so do not use them outside of the main threads when you use libqcr.

@j.wuttke I think this should also be mentioned in the documentation of libqcr

Resolves issue #7 (closed)

Merge request reports