Important: Please read the Qt Code of Conduct -

Problem in calling user defined class in dialog.

  • Hey! I am Burhan
    I am working on a periodic table in Qt c++.
    The theme is when you click on the button of an element the properties of the respective element appears in the dialog.
    Before working on the periodic table and design all buttons i want to test a one first.
    While running the code simultator shows no error but when i click on the button it show me nothing and the error generates in the bottom window in pink color as " QWidget::setLayout: Attempting to set QLayout "" on class1 "", which already has a layout" here is the code.

    dialog code.
    @#include "dialog.h"
    #include "ui_dialog.h"
    #include <QtGui>
    #include <QtCore>
    #include <class1.h>

    Dialog::Dialog(QWidget *parent) :
    ui(new Ui::Dialog)

    class1 OB1;

    delete ui;

    Here is the user defined class code.
    @#include "class1.h"
    #include <QtCore>

    class1::class1(QWidget *parent) :
    void class1 :: information (void)
    QGridLayout *point = new QGridLayout;
    QLabel *Calcium = new QLabel("Name");

    QLabel *Helium = new QLabel("Symbol");
    QLabel *Hydrogen = new QLabel("Atomic mass");
    QLabel *Nitrogen = new QLabel("Atomic Number");



    "this is the screen shot of the screen.. see the screen of mobile is blank after clicking on the pushbutton and as i clicked on the button it shows some error in the pink color on the status window.. ":

    Any help will highly be appriciated.

  • Moderators

    Your class1 constructor is calling class1::information() which sets the layout. Then in Dialog::Dialog() you're explicitly calling class1::information() again which tries to re-install a new layout.

  • then how can i resolve this problem ? sorry am not that much good at programming :(

  • Moderators

    Either remove line 15 from your first code snippet or line 9 from the second. OB1.information() is being called twice and, as such, class1::setLayout(point) is being called twice, which is what the error is referring to.

    This is pretty basic C++ stuff. It would be beneficial to make sure you've got the very basics down before embarking on a large project.

Log in to reply