Text is not updated in qwidget.
-
I created qwidget in qmainwindow, and then qwidget on it.
However, Text is not updated in the top QWidget.I have done a great deal of effort to solve this problem, but it has not been solved.
I've tried everything, including repaint, update, processEvents, but I still have problems.
Also, I tried with other widgets such as qlabel, lcd number, text edit,
The text was not updated.Label_SetVal->setText(SetValue);
/*
qApp->processEvents();
qApp->sendPostedEvents();
qApp->processEvents(QEventLoop::ExcludeUserInput);
Label_SetVal->repaint();
Label_SetVal->parentWidget()->repaint();
Label_SetVal->update();
Label_SetVal->parentWidget()->update();
*/ -
Hi and welcome to devnet,
Can you show how you initialise
Label_SetVal?
Where exactly are you callingsetTexton it ? -
@SGaist said in Text is not updated in qwidget.:
Can you show how you initialise Label_SetVal ?
Where exactly are you calling setText on it ?Thank you for your reply.
source code---------------------------------------------------------------------------
char keypadBuf[30] = {0,};
QLabel* Label_SetVal ;Label_SetVal = ui->lb_NetSetVal;
sprintf((char *)keypadBuf, "%s.%d", QByteArray(Label_SetVal ->text().toLocal8Bit()).data(),val);
SetValue = QString(keypadBuf);
Label_SetVal ->setText(SetValue);//qApp->processEvents(); //qApp->sendPostedEvents(); //qApp->processEvents(QEventLoop::ExcludeUserInput); //LB_SetVal->repaint(); //LB_SetVal->parentWidget()->repaint(); //LB_SetVal->update(); //LB_SetVal->parentWidget()->update(); -
@SGaist said in Text is not updated in qwidget.:
Can you show how you initialise Label_SetVal ?
Where exactly are you calling setText on it ?Thank you for your reply.
source code---------------------------------------------------------------------------
char keypadBuf[30] = {0,};
QLabel* Label_SetVal ;Label_SetVal = ui->lb_NetSetVal;
sprintf((char *)keypadBuf, "%s.%d", QByteArray(Label_SetVal ->text().toLocal8Bit()).data(),val);
SetValue = QString(keypadBuf);
Label_SetVal ->setText(SetValue);//qApp->processEvents(); //qApp->sendPostedEvents(); //qApp->processEvents(QEventLoop::ExcludeUserInput); //LB_SetVal->repaint(); //LB_SetVal->parentWidget()->repaint(); //LB_SetVal->update(); //LB_SetVal->parentWidget()->update();@sootoo23 said in Text is not updated in qwidget.:
sprintf((char *)keypadBuf, "%s.%d", QByteArray(Label_SetVal ->text().toLocal8Bit()).data(),val);
Wow, this looks really complicated.
Why not just use QString::arg(...)?SetValue = QString("%1.%2").arg(Label_SetVal ->text()).arg(val); -
@sootoo23 said in Text is not updated in qwidget.:
sprintf((char *)keypadBuf, "%s.%d", QByteArray(Label_SetVal ->text().toLocal8Bit()).data(),val);
Wow, this looks really complicated.
Why not just use QString::arg(...)?SetValue = QString("%1.%2").arg(Label_SetVal ->text()).arg(val); -
I need to pass the char buffer of "keypadBuf" to the C library.
It can not pass in the type of QString. -
@sootoo23 Is this label visible? Does it already have any text? Also, what are you doing after setting the text - do you maybe block the event loop with a loop?
Did you check what SetValue contains?@jsulm said in Text is not updated in qwidget.:
Is this label visible? Does it already have any text? Also, what are you doing after setting the text - do you maybe block the event loop with a loop?
Did you check what SetValue contains?yes, it is visible.
The default text is displayed when you load the initial QWidget.
The problem is that if you change the value by the number of characters, it will not update."printf("%s (%s)\n", keypadBuf, SetValue.toLocal8Bit().data());"
data is output well. -
@jsulm said in Text is not updated in qwidget.:
Is this label visible? Does it already have any text? Also, what are you doing after setting the text - do you maybe block the event loop with a loop?
Did you check what SetValue contains?yes, it is visible.
The default text is displayed when you load the initial QWidget.
The problem is that if you change the value by the number of characters, it will not update."printf("%s (%s)\n", keypadBuf, SetValue.toLocal8Bit().data());"
data is output well. -
Can you show the latest complete version of that part of your code ?
With only
I removed something and it still doesn't work, there's no way to debug your problem. -
Can you show the latest complete version of that part of your code ?
With only
I removed something and it still doesn't work, there's no way to debug your problem.------------mainwindow.cpp------------
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
...
...
#if (0)
//Removed endless loop timer
Hometimer = new QTimer(this);
connect(Hometimer, SIGNAL(timeout()),this,SLOT(HomeInfo_Update()));
Hometimer->start(1000);
#endif
}
void MainWindow::HomeInfo_Update()
{
...
...
ui->lb_HomeClk->setText(QString(TimeBuf));
...
}------------menuQwidget.cpp------------
wnd_menu::wnd_menu(QWidget *parent) :
QWidget(parent),
ui(new Ui::wnd_menu)
{
...
...
#if (0)
//Removed endless loop timer
Menu_Timer = new QTimer;
connect(Menu_Timer, SIGNAL (timeout()), this, SLOT(MenuInfo_Update()));
Menu_Timer->start(1000);
Menu_Timer->blockSignals(true);
#endif
}void wnd_menu::MenuInfo_Update()
{
...
...
ui->lb_MenuClk->setText(QString(TimeBuf));
...
...
} -
------------mainwindow.cpp------------
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
...
...
#if (0)
//Removed endless loop timer
Hometimer = new QTimer(this);
connect(Hometimer, SIGNAL(timeout()),this,SLOT(HomeInfo_Update()));
Hometimer->start(1000);
#endif
}
void MainWindow::HomeInfo_Update()
{
...
...
ui->lb_HomeClk->setText(QString(TimeBuf));
...
}------------menuQwidget.cpp------------
wnd_menu::wnd_menu(QWidget *parent) :
QWidget(parent),
ui(new Ui::wnd_menu)
{
...
...
#if (0)
//Removed endless loop timer
Menu_Timer = new QTimer;
connect(Menu_Timer, SIGNAL (timeout()), this, SLOT(MenuInfo_Update()));
Menu_Timer->start(1000);
Menu_Timer->blockSignals(true);
#endif
}void wnd_menu::MenuInfo_Update()
{
...
...
ui->lb_MenuClk->setText(QString(TimeBuf));
...
...
}- Are the slots you connected to the timers called?
- Is TimeBuf set when these slots are called?
//Removed endless loop timer - this is not the kind of endless loop I mentioned. It is fine to use timers this way. The problem is somewhere else. You need to debug your app or upload the code to somewhere so we can take a look.