'SetLayout of qt c++

please, help me to solve this probleme of qt; QWidget::setLayout: Attempting to set QLayout "" on Login_1 "Login_1", which already has a layout ?

Login_1::Login_1(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::Login_1)
{
    ui->setupUi(this);

    //The main windows
    QGridLayout* MainLayout = new QGridLayout();
    //The first ligne (username, line 0)
    QLabel* LbNom = new QLabel("User name");
    QLineEdit* LeNom = new QLineEdit();
    MainLayout->addWidget(LbNom,0,0);
    MainLayout->addWidget(LeNom,0,1);

    //The second line (password, line 1)
    QLabel* LbPassword = new QLabel("Password");
    QLineEdit* LePassword = new QLineEdit(this);
    MainLayout->addWidget(LbPassword,1,0);
    MainLayout->addWidget(LePassword,1,1);

    //Login Button(line 2)
    QPushButton* PbLogin = new QPushButton(this);
    PbLogin->setText("Login");
    MainLayout->addWidget(PbLogin,2,0);
    //setLayout(MainLayout);

}

Login_1::~Login_1()
{
    delete ui;
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source