Status texts from application



  • 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?



  • 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 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.