Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Displaying Widget in Dialog from code
-
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);
-
Thank you!!