Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QPlainText: not update after append text



  • I create a console window using QPlainTextEdit used to display my application status.

    It was created inside the app.ui.
    So, if I use appendPlainText() or appendHtml() from any method inside my App Class, it works good!

    But now, I have another class (*.ui) that need to send a message to the App Class and shows it on my QPlainTextEdit console.

    So I send a signal from my anotherClass with some text, like:

    class AnotherClass 
    {
    ...
    signals:
         sendMsg(QString msg);
    }
    
    class AppClass
    {
    ....
    slots:
        receiveMsg(QString msg);
    }
    
    AppClass::receiveMsg(QString msg)
    {
        // Append text Ok, but not refresh QPlainTextEdit.
        // It only shows the appended text when I manually scroll the QPlainTextEdit
        // Not auto "refresh" and not "auto scroll" to the bottom
        ui->qplaintextedit->appendPlainText(msg);
    
        // I ALREADY TRIED:
        // A)
        // int v = ui->qplaintextedit->verticalScrollBar()->maximum();
        // ui->qplaintextedit->verticalScrollBar()->setValue(v);
    
        // B)
        // ui->qplaintextedit->setCenterOnScroll(true);
        // ui->qplaintextedit->centerCursor();
    
        // C)
        // ui->qplaintextedit->show();
    }
    

    In this case (signal and slot) how can I auto refresh and scroll the QPlainTextEdit to the bottom?


  • Lifetime Qt Champion


  • Lifetime Qt Champion

    Hi,

    What does that other class do ?
    Does it do any heaving computation ?



  • @SGaist at this time...no.
    The AnotherClass is simple...I just want to send a msg from AnotherClass to AppClass and see it on the QPlainText console with auto refresh and scroll to the bottom line.

    In the future, may be, I will implemente other classes that will have some heavy computation power.

    Could you help me?



  • Any ideas?


  • Qt Champions 2019

    @fem_dev said in QPlainText: not update after append text:

    Any ideas?

    What OS do you have? Did you also search the Qt bug tracker?
    Please provide a minimal example so we can test it locally.



  • @Christian-Ehrlicher
    I copied my Qt project from a Mac OSX Catalina machine to another computer that is running Ubuntu 20.04.

    When I run it on Ubuntu, it works perfect! No issues.

    It automatically "refresh" and scroll to the bottom line.


    A simple example:

    AnotherClass::AnotherClass()
    {
        emit sendMsg("This is a msg from anotherClass");
    }
    
    AppClass::receiveMsg(QString msg)
    {
        ui->qplaintextedit->appendPlainText(msg);
    }
    

    May be this problem is just in OSX Catalina....I don't know...

    Important: Both OSX Catalina and Ubuntu 20.04 machines are running:

    • Qt Creator 4.12.3
    • Qt 5.15

    Please, tell me if you need more details...


  • Lifetime Qt Champion

    Emitting a signal in a constructor is a bad idea as you can't have connected it to a slot at that point in time.



  • @SGaist sorry....

    I just put the emit in the constructor only in this simple example, but int my real code this emit is outside the class constructor...

    I did it here just to explain my question.

    The key point is that:
    The receiveMsg() was triggered and I got the QString msg with success.
    I think that the msg is already appended to my qplaintextedit, but this widget IS NOT SHOWING automatically the appended msg. May be the QPlainTextEdit UI is not rendering as it should be.

    So, after that, if I MANUALLY scroll the QPlainTextEdit vertically up and down, this widget "refresh" and shows the appended msg at the bottom line.

    Any ideas?

    May be this problem is just in OSX Catalina....I don't know...

    Important: Both OSX Catalina and Ubuntu 20.04 machines are running:

    • Qt Creator 4.12.3
    • Qt 5.15

  • Qt Champions 2019

    Since it seems to be easy to reproduce I would create a testcase and open a bug report.



  • @Christian-Ehrlicher It's my first time reporting a possible bug...

    Where should I report it? Do you have a link?


  • Lifetime Qt Champion


Log in to reply