Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Displaying Widget in Dialog from code
QtWS25 Last Chance

Displaying Widget in Dialog from code

Scheduled Pinned Locked Moved Solved General and Desktop
dialogwidget
3 Posts 2 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gabor53
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      hi
      u need to give it "this" as parent
      new QLabel(this);

      1 Reply Last reply
      1
      • G Offline
        G Offline
        gabor53
        wrote on last edited by
        #3

        Thank you!!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved