Solved 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 useappendPlainText()
orappendHtml()
from any method inside myApp
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 myQPlainTextEdit
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
andslot
) how can I auto refresh and scroll theQPlainTextEdit
to the bottom? -
-
Hi,
What does that other class do ?
Does it do any heaving computation ? -
@SGaist at this time...no.
TheAnotherClass
is simple...I just want to send a msg fromAnotherClass
toAppClass
and see it on theQPlainText
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?
-
@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...
-
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 thisemit
is outside the class constructor...I did it here just to explain my question.
The key point is that:
ThereceiveMsg()
was triggered and I got theQString msg
with success.
I think that themsg
is already appended to myqplaintextedit
, but this widget IS NOT SHOWING automatically the appendedmsg
. May be theQPlainTextEdit
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 appendedmsg
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
-
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?
-