Important: Please read the Qt Code of Conduct -

Opening dynamically created buttons

  • I tried to make some dynamically created buttons but the appllication closed when I try to do it or make every buttons in one position in a frame (when a I do it in new window it works but I need in a special created frame several buttons)

    void MainWindow::createButtons(){

    //this line makes a problem

    // QVBoxLayout *layout=new QVBoxLayout(); //this works

    QPushButton *przyc =new QPushButton(buttontext, ui->frame);
    QPushButton *przyc2 =new QPushButton(buttontext, ui->frame);


    My QT creator 2.7.2 on base qt 5.1.0 version under linux mint

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    @Romi11 said in Opening dynamically created buttons:


    You do not check whether the value is null.

    I guess that you did not apply a layout on your frame in designer.

  • You right the pointer is null however I applied in Qt creator layout and frame . How to do it correctly?

  • Lifetime Qt Champion


    Go to Designer and look what the Layout really is named.

    alt text

    Then it's available as

    and see if that works;

    Also you can avoud casting as its of correct layout type already.

  • now it works how I supposed. I think its difficult to achieve it, without your support I would have spent many hours until find it correctly

  • Lifetime Qt Champion

    Well, Its unclear why layout() didn't work.
    It does return the layout for me in a small example.

    So I think maybe you changed the type of the layout
    and hence when you cast it becomes zero as it was not the right type.

    Or something like that.

  • @mrjj I think I do it how in example but the philosophy of qt frames and layouts I should to learn more.
    Thanks for quick answers :)

Log in to reply