[Bug] Why QDialog display empty rarely.
Unsolved
General and Desktop
-
#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); }
-
@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()) {
}
} -
Maybe related to https://forum.qt.io/topic/107728/qscrollarea-causes-crash-on-close/4 ? Please try with 5.12.5