PDA

View Full Version : ‎a lightweight text showing widget



jacum
22nd August 2007, 13:39
Good morning to all!

I am writing an application which is reading packets from a socket.

There is a main window which includes a QTextEdit.
Then there is a thread which listens to the socket and when a
packet arrives does a postEvent to the QTextEdit containing the information
necessary to print the packet details on the QTextEdit itself.

The QTextEdit provides me a scrollbar and the capability of printing
the information in different colors, which are two features which are necessary
to my application.

Before going on i tell you that my application was a command line one
before i decided to turn it into a QT GUI... and the packet was printed
via a "printf()" as it was received from the socket.

The problems i encountered are 2:

- the QTextEdit does not provide a method to set a buffer to limit the number
of lines to display
(after N lines printed, i am no more interested in the old information and i do
not want it to be displayed in the text buffer) -> this is what the console does
and a feature i would need...)
Actually i keep a counter of the lines i append(), and then delete with the help
of the QTextCursor the oldest line at the beginning of the TextEdit...

- the whole system ( append() + first line deleting) is very slow if the number
of packets read on the socket is high in time...

Finally, i would like to do the same thing that does `konsole` for instance, that is
be efficient and automatically delete the old lines of text!

I do not know if there is a simple way of using the QT classes to do this or if it
would be simpler to integrate a `konsole` itself inside my mainwindow.. (using kParts??)

Any help or hint would be appreciated!

Thanks in advance!

GIacomo strangolino, Italy

darksaga
22nd August 2007, 14:44
here's my idea:

1. create a simple containerclass containing your connectionDetails in a QStringList, or equivalent QList <connectionDetails >
use signal slot mechanism to add new details, if listcount exceeds your limit, remove the first element and a new one

2. to view your connectiondetails use a QListView with a model derived from QAbstractListModel, in your model u access the container above

this should be faster, than the qtextedit method and will show only the number of messages you specify

regards