Question

I have a message source. This constantly emits signals for log messages. These log messages should be visualized in some way in the user interface. Since there are a lot messages (up to 100 per second in peak situations) this must happen quite efficiently.

For this I had 2 approaches:

  1. Using a QTextEdit

    • This doesn't worked well. Using insertHtml and positioning the curser took a long time. For this the UI began to be unreponsive
  2. Using a a QTableView with an attached QAbstractTableModel

    • The data is inserted to the model. This automatically updates the view. Additionally the dataChanged-signal is connected to QTableView::scrollToBottom so that always the new messages are shown.

Unfortunately both approaches don't work efficient enough. The second one is better but scrolling down to the bottom needs a lot of ressources.

Can someone help me with a better solution to display log messages?

Was it helpful?

Solution

Both QTextEdit and QPlainTextEdit are quite slow and unsuitable for anything but the most minor logging. The formatting operations they perform are very expensive and not designed for log use - in practice, fast logging to a text edit ends up locking up the GUI.

The QTableView, or even QListView, are very fast in comparison. Note that the model that is appended to does not emit dataChanged signal - because no existing data is changed, and that's the signal's meaning. The model is emitting the rowsInserted signal after each insertion (among other signals).

The list view needs some tweaks to behave fast, see this answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top