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. QButtonGroup - cannot check initial button
Forum Updated to NodeBB v4.3 + New Features

QButtonGroup - cannot check initial button

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 1.7k 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.
  • N Offline
    N Offline
    never_ever
    wrote on last edited by
    #1

    Hi,
    I create QButtonGroup, but I don't know how to do initial checking.
    I've tried simple setChecked(bool) method, but it causes app crash.

    m_boxSingle = new QCheckBox(tr("Single calibration"));  
    m_boxStereo = new QCheckBox(tr("Stereo calibration"));
    
    connect(m_boxSingle, SIGNAL(toggled(bool)), this, SLOT(setSingleCalibration(bool)));
    connect(m_boxStereo, SIGNAL(toggled(bool)), this, SLOT(setStereoCalibration(bool)));
    
    QVBoxLayout* vBoxType = new QVBoxLayout(typeCalibBox);
    vBoxType->addWidget(m_boxSingle);
    vBoxType->addWidget(m_boxStereo);
    
    QButtonGroup* typeCalibGroup = new QButtonGroup(typeCalibBox);
    typeCalibGroup->addButton(m_boxSingle);
    typeCalibGroup->addButton(m_boxStereo);
    //m_boxSingle->setChecked(true);  //<-- here I get error
    typeCalibGroup->setExclusive(true);
    

    Is there any different way to initial check?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Did you check with a debugger the content of m_boxSingle ?

      Is your code sample all called in a single function ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • N Offline
        N Offline
        never_ever
        wrote on last edited by
        #3

        If you look in above code I have two connections there.

        connect(m_boxSingle, SIGNAL(toggled(bool)), this, SLOT(setSingleCalibration(bool)));
        connect(m_boxStereo, SIGNAL(toggled(bool)), this, SLOT(setStereoCalibration(bool)));
        

        In my GUI I have one QGroupBox, where user can choose from two options: single or stereo calibration. Depending on user choice in second QGroupBox (showed in code in first post) he can choose one (for single) or two (for stereo) cameras. So I created that connections to change exlusive option for second group.

        void Calibration::setSingleCalibration(bool checked)
        {
            for (int i = 0; i < m_cameraCheckBox.size(); i++)
                m_cameraCheckBox[i]->setChecked(false);
        
            if(m_cameraCheckBox.size() > 0)
                m_cameraCheckBox[0]->setChecked(true);
            m_cameraGroup->setExclusive(true);
        }
        
        void Calibration::setStereoCalibration(bool checked)
        {
            m_cameraGroup->setExclusive(false);
        }
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Why not use QRadioButton ? Looks like a better widget for selecting only one option.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • N Offline
            N Offline
            never_ever
            wrote on last edited by never_ever
            #5

            I thought that QChecBox is better choice because sometimes I choose only one option and sometimes more than one option. It depends on what is user's first choice. If he/she chooses single calibration option then second button group should be exclusive, if he/she chooses stereo calibration option then second button group should not be exclusive.

            However I checked QRadioButton, and it also causes app crash

            jsulmJ 1 Reply Last reply
            0
            • N never_ever

              I thought that QChecBox is better choice because sometimes I choose only one option and sometimes more than one option. It depends on what is user's first choice. If he/she chooses single calibration option then second button group should be exclusive, if he/she chooses stereo calibration option then second button group should not be exclusive.

              However I checked QRadioButton, and it also causes app crash

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @never_ever App crash? Then you most probably dereference an invalid pointer. Did you try to debug to see where it crashes?

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

              1 Reply Last reply
              0
              • N Offline
                N Offline
                never_ever
                wrote on last edited by
                #7

                Ok,. I found where problem is. I make two connections. One of them was connection to slot setSingleCalibration(), and that slot made troubles, because it was called before creating second group of buttons that were used in that slot. My mistake :P

                1 Reply Last reply
                0

                • Login

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