Displaying Widget in Dialog from code
Solved
General and Desktop
-
Hi,
I'm trying to display sum_Label in MainWindow but instead it opens a new window and displays the label in the new window.#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); int num1 = 3; int num2 = 5; add(num1, num2); } MainWindow::~MainWindow() { delete ui; } void MainWindow::add(int num1, int num2) { int sum = num1 + num2; QString sumvalue = QString::number (sum); QLabel *sum_Label = new QLabel(); sum_Label->setText (sumvalue); sum_Label->show (); }
What can I do to display the label in the MainWindow?
Thank you. -
hi
u need to give it "this" as parent
new QLabel(this);