0
votes

i am new at QT

i created a window and i want to add a button on this window but the button is opened in different window.

How to add this button to default window

Here is my code;

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QPushButton"
#include "QDesktopWidget"
#include <iostream>

using namespace std;
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    QPushButton* buton1 = new QPushButton("Hello");
    buton1 -> setGeometry(QRect(QPoint(100,100),QSize(200,50)));
    connect(buton1, &QPushButton::released, this, &MainWindow::buton_fonk);
    buton1 -> show();
    ui->setupUi(this);
}

void MainWindow::buton_fonk()
{
    cout << "here" << endl;
}

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

main.cpp

#include "mainwindow.h"
#include <QApplication>
#include <QDesktopWidget>


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.setWindowState(Qt::WindowMaximized);

    w.showFullScreen();

    return a.exec();
}