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
Forum Updated to NodeBB v4.3 + New Features

Displaying Widget in Dialog from code

Scheduled Pinned Locked Moved Solved General and Desktop
dialogwidget
3 Posts 2 Posters 1.2k Views 1 Watching
  • 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 30 Jan 2016, 16:25 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
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 30 Jan 2016, 16:32 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 30 Jan 2016, 16:38 last edited by
        #3

        Thank you!!

        1 Reply Last reply
        0

        3/3

        30 Jan 2016, 16:38

        • Login

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