[Solved] Can not set the layout of Groupbox



  • Hi,

    I created a Qt Designer Form Class and my ui consist a groupbox.

    I'm trying to programmaticaly add radioButtons to that. I'm using below code.

    @Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
    {
    QString size;
    QRadioButton *rb;
    QGridLayout *grid = new QGridLayout();

    foreach(size, existingSizes())
      {
           rb = new QRadioButton();
           rb->setText(size);
           grid->addWidget(rb);
      }
    ui->groupBox->setLayout(grid);
    ui->setupUi(this);
    

    }@

    At run time application crashes.

    What is happening? I need your help.

    Thanks in advance.


  • Moderators

    the problem is this:
    @
    ui->groupBox->setLayout(grid);
    ui->setupUi(this);
    @

    You try to access ui->groupBox before it's getting initlized in the next step. So switch these 2 lines and the crash should be resolved.



  • Ohhh...

    Thank you..


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.