Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Status texts from application
QtWS25 Last Chance

Status texts from application

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 912 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zerby
    wrote on last edited by
    #1

    I've created a pretty simple widget, which is used as a text area to display status texts for the user. For example, when downloading files in another thread, a QString is emitted and it's then added as a line of text to this widget's QLabel -object.

    I have a issue with it however. It's slow, when handling for example ~20-30 lines of text within few seconds. And it get's increasingly slow as the widget fills with text. I've tried different approaches, and this is working best so far, eventhough it is rather clunky:

    @
    void textArea::add(QString text)
    {
    // If the text area is blocked (too many messages), return without adding the text
    if (this->is_blocked) return;

    // Add time stamp
    if (this->addTimeStamp) text.insert(0, qtimestamp() + " ");
    
    // Construct the text
    QString new_text = this->text_label->text();
    new_text.push_front("\n\n");
    new_text.push_front(text);
    
    // Set the text to the label
    this->text_label->setText(new_text);
    
    // If the text's length is over 40000 characters, block the text area
    // This is needed as text area will otherwise gather too big amount of
    // text and might cause the application to crash.
    if (new_text.length() > 40000) this->block();
    QCoreApplication::processEvents();
    

    }@

    So basicly, the text of the member object (QLabel) text_label is extracted, a new line added to it and then appended with the given parameter. I also tried creating different QLabel's for each added line, but that was a lot worse...

    So, I guess this is fundamendally wrong way to to this kind of widget.. But does anyone have any suggestions?

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Why do you use a QLabel for it? (If I understand correctly that your text_label is indeed a QLabel). Why not a QTextBrowser? This is more suitable for handling of added text. It even is able to keep scolling down when new text is entered.
      There is also no need to call the processEvents() function. When you're in a slot, ending it will automatic check the event queue for more event.

      Greetz, Jeroen

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        Zerby
        wrote on last edited by
        #3

        [quote author="Jeroentje@home" date="1399619632"]Why do you use a QLabel for it? (If I understand correctly that your text_label is indeed a QLabel). Why not a QTextBrowser? This is more suitable for handling of added text. It even is able to keep scolling down when new text is entered.
        There is also no need to call the processEvents() function. When you're in a slot, ending it will automatic check the event queue for more event.
        [/quote]

        I will try QTextBrowser, thank you. text_label was a QLabel indeed. I had created a QScrollArea around the widget, so scrolling was of course happening already.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved