Results 1 to 2 of 2

Thread: ‎a lightweight text showing widget

  1. #1
    Join Date
    Aug 2007
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default ‎a lightweight text showing widget

    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

  2. #2
    Join Date
    Jan 2007
    Posts
    68
    Thanks
    9
    Thanked 8 Times in 8 Posts

    Default Re: ‎a lightweight text showing widget

    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

  3. The following user says thank you to darksaga for this useful post:

    johnmauer (17th January 2010)

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 10:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.