Hi, I am new for Qt, i am trying to display 0 to 999 in text Browser but when i am executing following code it is directly showing 999 output can anyone help me, thank you in advance
-
@Rameshwar like @JonB said, that is possible, but will look complicated
#include <QApplication> #include <QTextBrowser> #include <QTimer> int main(int argc, char *argv[]) { QApplication a(argc, argv); QTextBrowser *browser = new QTextBrowser(); browser->setPlainText("0"); browser->show(); QTimer *t = new QTimer(); int count = 0; QObject::connect(t, &QTimer::timeout, browser, [&count, t, browser]()->void{ if(++count < 100){ browser->append(QString::number(count)); } else { t->stop(); } }); t->start(1000); return a.exec(); }
-
Hi,
How is it not useful ? The QTimer approach is the right one if you want to display a progressive counter in a way that your application user can see it.
Using a loop like you do just blocks the event loop. That's why you only see the widget content after the loop ended.
-
@Rameshwar If you need this code inside mainwindow then put it there, it isn't that hard.
-
@jsulm
but if you write code inside mainwindow then , it does not display step by step directly it displays last value that is 999 or using append it displays 0,1,2.....999 once time but i want it displays step by step first it display "1" then increment (i++) then it display "2" then and again it (i++) increment by one and display 3....999. -
@Rameshwar Then you're doing it wrong. Please show your code.
-
@Rameshwar This code is NOT what @J-Hilk suggested...
-
@Rameshwar This is exactly what was already suggested (using QTimer). Did you try?!
-
@Rameshwar said in Hi, I am new for Qt, i am trying to display 0 to 999 in text Browser but when i am executing following code it is directly showing 999 output can anyone help me, thank you in advance:
i want to display contineousaly some data after one second on window.ui
everyone here understood your requirement! Solutions are suggested ! why don't you try instead of repeating the same thing over &over ?
-
-
@J-Hilk has given you the necessary code to start from. That's why people type in answers to questions. First try that and verify it works.
-
Then change it so that it writes on your mainwindow or whatever you want instead.
-
Only after that, write back if you can't get what you want working.
-