Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Bug] Why QDialog display empty rarely.
Forum Updated to NodeBB v4.3 + New Features

[Bug] Why QDialog display empty rarely.

Scheduled Pinned Locked Moved Unsolved General and Desktop
17 Posts 5 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • VRoninV VRonin

    without any code it's like guessing the number of water drops in the Atlantic ocean.

    brucezcgB Offline
    brucezcgB Offline
    brucezcg
    wrote on last edited by VRonin
    #4

    @VRonin

    #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);
    }
    
    jsulmJ 1 Reply Last reply
    0
    • brucezcgB brucezcg

      @VRonin

      #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);
      }
      
      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #5

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      brucezcgB 1 Reply Last reply
      3
      • VRoninV VRonin

        without any code it's like guessing the number of water drops in the Atlantic ocean.

        brucezcgB Offline
        brucezcgB Offline
        brucezcg
        wrote on last edited by
        #6

        @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.

        1 Reply Last reply
        0
        • brucezcgB Offline
          brucezcgB Offline
          brucezcg
          wrote on last edited by
          #7

          Just like the dialog doesn't call paint() automatically.

          1 Reply Last reply
          0
          • jsulmJ jsulm

            @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.

            brucezcgB Offline
            brucezcgB Offline
            brucezcg
            wrote on last edited by
            #8

            @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()) {
            }
            }

            jsulmJ 1 Reply Last reply
            0
            • brucezcgB brucezcg

              @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()) {
              }
              }

              jsulmJ Online
              jsulmJ Online
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #9

              @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.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              brucezcgB 1 Reply Last reply
              1
              • jsulmJ jsulm

                @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.

                brucezcgB Offline
                brucezcgB Offline
                brucezcg
                wrote on last edited by
                #10

                @jsulm Qt 5.12.3 mingw7 32bit.
                This phenomena is never occur on my PC, It occurred on my college's PC rarely.

                jsulmJ 1 Reply Last reply
                0
                • brucezcgB brucezcg

                  @jsulm Qt 5.12.3 mingw7 32bit.
                  This phenomena is never occur on my PC, It occurred on my college's PC rarely.

                  jsulmJ Online
                  jsulmJ Online
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #11

                  @brucezcg What is the OS on that PC and graphics driver?

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  brucezcgB 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @brucezcg What is the OS on that PC and graphics driver?

                    brucezcgB Offline
                    brucezcgB Offline
                    brucezcg
                    wrote on last edited by
                    #12

                    @jsulm Win10 & Intel HD Graphics 520

                    jsulmJ 1 Reply Last reply
                    0
                    • brucezcgB brucezcg

                      @jsulm Win10 & Intel HD Graphics 520

                      jsulmJ Online
                      jsulmJ Online
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #13

                      @brucezcg Try to update the graphics driver.

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      brucezcgB 1 Reply Last reply
                      1
                      • jsulmJ jsulm

                        @brucezcg Try to update the graphics driver.

                        brucezcgB Offline
                        brucezcgB Offline
                        brucezcg
                        wrote on last edited by
                        #14

                        @jsulm But this is very rarely. most of the time the dialog display well.

                        mrjjM 1 Reply Last reply
                        0
                        • brucezcgB brucezcg

                          @jsulm But this is very rarely. most of the time the dialog display well.

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #15

                          @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.

                          brucezcgB 1 Reply Last reply
                          0
                          • mrjjM mrjj

                            @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.

                            brucezcgB Offline
                            brucezcgB Offline
                            brucezcg
                            wrote on last edited by
                            #16

                            @mrjj Thanks for the reply, and I try to use QWidget instead of QDialog.

                            1 Reply Last reply
                            0
                            • Christian EhrlicherC Offline
                              Christian EhrlicherC Offline
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on last edited by
                              #17

                              Maybe related to https://forum.qt.io/topic/107728/qscrollarea-causes-crash-on-close/4 ? Please try with 5.12.5

                              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                              Visit the Qt Academy at https://academy.qt.io/catalog

                              1 Reply Last reply
                              1

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved