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. [Solved] Can not set the layout of Groupbox
QtWS25 Last Chance

[Solved] Can not set the layout of Groupbox

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.2k Views
  • 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 Offline
    H Offline
    Hareen Laks
    wrote on last edited by
    #1

    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
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      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
      0
      • H Offline
        H Offline
        Hareen Laks
        wrote on last edited by
        #3

        Ohhh...

        Thank you..

        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