Unsolved [Bug] Why QDialog display empty rarely.
-
I create a class inherit from QDialog. it run well most of the time, but rarely display empty.
The good one looks like this.
And the abnormal status like this.
-
Any one can help?
-
without any code it's like guessing the number of water drops in the Atlantic ocean.
-
#include "dlgbank.h" #include "ui_dlgbank.h" DlgBank::DlgBank(QWidget *parent) : QDialog(parent), ui(new Ui::DlgBank) { ui->setupUi(this); setWindowTitle(tr("BANK")); setWindowFlags(windowFlags()&~Qt::WindowContextHelpButtonHint); //Row Enable ZWgtHMITitle* title = new ZWgtHMITitle(this); ui->hLayoutEnable->addWidget(title, 10); title->setTitles(tr("Enable")); for(int col=1; col<9; col++) { QHBoxLayout* layout = new QHBoxLayout(this); HZSwitch* edt=new HZSwitch(this); layout->addWidget(edt); layout->setAlignment(edt,Qt::AlignCenter); mSWEnables.push_back(edt); connect(edt, &HZSwitch::toggled, this, &DlgBank::slt_swToggled); ui->hLayoutEnable->addLayout(layout, 5); } //Row Exposure title = new ZWgtHMITitle(this); ui->gridLayout->addWidget(title,0,0); ui->gridLayout->setColumnStretch(0,10); for(int col=1; col<9; col++) { ui->gridLayout->setColumnStretch(col, 5); { ZLineEdit* edt=new ZLineEdit(this); edt->setIgnoreNotChange(false); vector<HVarUI> vars; mEdtExposures.push_back(edt); HVarUICommon::addInt(vars, HCMDFULLTAG_END, tr("Exposure(us)"), 1200, 25, 999999); HVarUICommon::cfgUiItem(vars.at(0), title, edt); connect(edt, &ZLineEdit::sig_edtFinish, this, &DlgBank::slt_edtFinish); ui->gridLayout->addWidget(edt,0,col); edt->clearFocus(); } } //Row Gain title = new ZWgtHMITitle(this); ui->gridLayout->addWidget(title,1,0); for(int col=1; col<9; col++) { ZComboBox* cbx=new ZComboBox(this); mCbxGains.push_back(cbx); vector<HVarUI> vars; vector<pair<int, QString>> parms; parms.push_back(make_pair(1, tr("1"))); parms.push_back(make_pair(2, tr("2"))); parms.push_back(make_pair(3, tr("3"))); parms.push_back(make_pair(4, tr("4"))); parms.push_back(make_pair(6, tr("6"))); parms.push_back(make_pair(8, tr("8"))); HVarUICommon::addList(vars, HCMDFULLTAG_END, tr("Gain"), parms, 4); HVarUICommon::cfgUiItem(vars.at(0), title, cbx); connect(cbx, SIGNAL(currentIndexChanged(int)), this, SLOT(slt_currentIndexChanged(int))); ui->gridLayout->addWidget(cbx,1,col); } this->setFixedSize(800,200); setTabOrder(mSWEnables.last(),mEdtExposures.first()); } DlgBank::~DlgBank() { delete ui; } void DlgBank::setBanks(const QList<Bank> &banks) { mBanks = banks; for(int i=0; i<mBanks.length()&&i<8; i++) { const Bank bk = mBanks.at(i); mSWEnables[i]->setToggle(bk.mbEnable); mEdtExposures[i]->setText(QString::number(bk.mExposure)); mCbxGains[i]->setCurrentByVal(bk.mGain); } } void DlgBank::slt_currentIndexChanged(int index) { Q_UNUSED(index) } void DlgBank::slt_edtFinish(const QString &txt) { ZLineEdit* edt = static_cast<ZLineEdit*>(sender()); edt->clearFocus(); int idx = mEdtExposures.indexOf(edt); if(mBanks.length()>idx && idx>=0 && !txt.isEmpty() ) { mBanks[idx].mExposure = txt.toUInt(); QString cmd = HMenuProtocol::pack_BANK(mBanks); if(!cmd.isEmpty()) { menu_commands(cmd); } } } void DlgBank::slt_swToggled(bool bToggle) { int idx = mSWEnables.indexOf(static_cast<HZSwitch*>(sender())); if(mBanks.length()>idx && idx>=0) { mBanks[idx].mbEnable = bToggle; QString cmd = HMenuProtocol::pack_BANK(mBanks); if(!cmd.isEmpty()) { menu_commands(cmd); } } } void DlgBank::send_cmd(const CmdFrame &cmd) { emit sig_send_cmd(cmd); }
-
@brucezcg Can you also show how you create the dialog and show it?
If the dialog is empty then most probably your event loop is blocked. -
@VRonin The phenomena is strange, in the empty status, although I couldn't see the controls(such as the switch button) but if I move mouse to the position of the button(it should be), all the controls will turn to display.
-
Just like the dialog doesn't call paint() automatically.
-
@jsulm Thanks.
I create the dialog in a Wdiget's constructor function like this.
{
……
mDialogBank = new DlgBank(this);
}//Click button display the dialog.
void Wgt_Tuning::on_btnBank_clicked()
{
//Display the dialog.
if (QDialog::Accepted == mDialogBank->exec()) {
}
} -
@brucezcg On which platform do you have this behaviour?
You also could try to run through debugger and check the stack trace when this happens. -
@jsulm Qt 5.12.3 mingw7 32bit.
This phenomena is never occur on my PC, It occurred on my college's PC rarely. -
@brucezcg What is the OS on that PC and graphics driver?
-
@jsulm Win10 & Intel HD Graphics 520
-
@brucezcg Try to update the graphics driver.
-
@jsulm But this is very rarely. most of the time the dialog display well.
-
@brucezcg
Hi
maybe a rare driver bug. :)In any case, if possible you should test if a new driver helps on your college's PC.
-
@mrjj Thanks for the reply, and I try to use QWidget instead of QDialog.
-
Maybe related to https://forum.qt.io/topic/107728/qscrollarea-causes-crash-on-close/4 ? Please try with 5.12.5