View Full Version : QLineEdit can't update inside QStackedWidget
lwz
20th March 2014, 09:28
While a QStackedWidget adds several widgets , QLineEdit inside the QStackedWidget can't update .
Is that a QStackedWidget bug or I miss something ?
please help.
anda_skoa
20th March 2014, 10:25
What do you mean with "can't update"?
If you set a text it doesn't change?
You can't type into it?
Cheers,
_
lwz
20th March 2014, 10:53
I can type into it ,but it fail when I use setText().
anda_skoa
20th March 2014, 13:33
Very strange.
Just to be sure: you are calling setText() on the correct line edit, right? I.e. there is no other line edit than the one being displayed.
Can you create a minimal example that shows the problem?
Cheers,
_
lwz
20th March 2014, 14:17
It works well in a minimal example , but it doesn't within my code .
In my code , it is ok when the stackedwidget adds no more than 5 widgets.. When up to 6, 7,,it fails sometimes.
It definitely goes wrong with more than 8 widgets(Eache of these widgets contains about 20 qwidgets,llike button,qlineedit ,qdoublespinbox etc.).
Lesiok
20th March 2014, 15:07
How You recognize which QLineEdit should be updated ? Show some code.
lwz
20th March 2014, 15:17
Thansands of lines ,,,minimal example can't make it goes wrong.
wysota
20th March 2014, 16:41
Show us code where you initialize widgets in the stacked view and how you later try to call setText() on the proper line edit.
lwz
22nd March 2014, 04:05
if I have initialized widgets in a wrong way , how can it work just fine when adding 3 or 4 widgets?
Added after 16 minutes:
This a slice of my code
QStackedWidget *TraceConfigDialog::buildStackedWidget()
{
QStackedWidget *stackedWidget = new QStackedWidget();
stackedWidget->addWidget(linearGroupBox());
stackedWidget->addWidget(fillingGroupBox());
#if 1 // here if I put this "#if 1" on the 5th line , qlineedit can't update , actually all widgets inside the stacedwidget can't update.
stackedWidget->addWidget(imageGroupBox());
stackedWidget->addWidget(textGroupBox());
stackedWidget->addWidget(logGroupBox());
stackedWidget->addWidget(waveGroupBox());
stackedWidget->addWidget(depthGroupBox());
stackedWidget->addWidget(timeGroupBox());
stackedWidget->addWidget(tadpoleGroupBox());
#endif
return stackedWidget;
}
void inti()
{
vlayout=new QVBoxLayout();
vlayout->addWidget(listWidget);
vlayout->addWidget(curveStyleLabel);
vlayout->addWidget(curveStyle);
layout=new QHBoxLayout();
layout->addLayout(vlayout);
stackedWidget = buildStackedWidget(); // <----
m_rightLayout = new QVBoxLayout();
m_rightLayout->addWidget(stackedWidget,10);
layout->addLayout(m_rightLayout);
layout->addStretch();
widget->setLayout(layout);
}
QPushButton *recommendButton = new QPushButton(tr("Recommend Value"));
connect(recommendButton,SIGNAL(clicked()),this,SLO T(handleRecommendValue()));
void TraceConfigDialog::handleRecommendValue()
{
m_linearLeftValue->setText("testest); // <--- m_linearLeftValue is a QLineEdit
m_linearLeftValue->update();
stackedWidget->update();
}
The QLineEdit is inside linearGroupBox() , which return a QGroupBox. And there is a QPushButton inside the linearGroupBox()
Lesiok
22nd March 2014, 08:08
Where m_linearLeftValue is initialized ? I think that it is initialized many times.
P.S.
TraceConfigDialog::handleRecommendValue() should look like :
void TraceConfigDialog::handleRecommendValue()
{
m_linearLeftValue->setText("testest); //m_linearLeftValue is a QLineEdit
}
lwz
22nd March 2014, 10:29
I know the two lines in handleRecommendValue() is useless.
Speaking of initializing, I do have the stackedwidget initialized many times, because I found it couldn't update. However, I have not found this trick back then, it was related to stackedwidegt' adding widgets.
anda_skoa
22nd March 2014, 11:59
Your comment for the #if 1 doesn't make sense, i.e. it doesn't matter where you put it because everything between it and #endif will be part of the compiled source code.
foo();
#if 1
bar();
#endif
and
#if 1
foo();
bar();
#endif
result in exactly the same code after preprocessing.
Cheers,
_
lwz
25th March 2014, 02:52
anda_skoa, thanks for your replay.
I get what you mean , it was #if 0 when I tested how many widgets to be added would cause that problem.
ChrisW67
25th March 2014, 03:50
Where is m_linearLeftValue initialised?
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.