Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [Solved] Can not set the layout of Groupbox

    General and Desktop
    2
    3
    996
    Loading More Posts
    • 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.
    • H
      Hareen Laks last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators last edited by

        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.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply Reply Quote 0
        • H
          Hareen Laks last edited by

          Ohhh...

          Thank you..

          1 Reply Last reply Reply Quote 0
          • First post
            Last post