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. Difficulty in Qlabel and POO

Difficulty in Qlabel and POO

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 294 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
    Gutoficiall
    wrote on last edited by
    #1

    I'm having trouble updating the value of label_Number, which I defined in my interface (myDialog.ui)
    When I click on MainWindow::on_pushButton_clicked, through my MainWindow.

    MainWindow.h and .cpp:

    void MainWindow::on_pushButton_clicked(){
        obj.setNumber(ui->lineEdit_Number->text().toInt());
        qDebug() << obj.getNumber();
        myDialog ptr; ptr.exec();
    }
    

    myDialog.h:

    myDialog(Qwidget *parent) : QDialog(parent), ui(new Ui::myDialog){
    	ui->setupUi(this);
    	myClass obj;
    	 ui->label_Number->setText(QString::number(obj.getNumber()));
    }
    

    In my case, I would have to create a Qlabel as private in my myDialog, and making a method to access
    my ui->label_Number, being able to update the value directly from my MainWindow button, without having to create a button inside myDialog to refresh;

    JonBJ 1 Reply Last reply
    0
    • G Gutoficiall

      I'm having trouble updating the value of label_Number, which I defined in my interface (myDialog.ui)
      When I click on MainWindow::on_pushButton_clicked, through my MainWindow.

      MainWindow.h and .cpp:

      void MainWindow::on_pushButton_clicked(){
          obj.setNumber(ui->lineEdit_Number->text().toInt());
          qDebug() << obj.getNumber();
          myDialog ptr; ptr.exec();
      }
      

      myDialog.h:

      myDialog(Qwidget *parent) : QDialog(parent), ui(new Ui::myDialog){
      	ui->setupUi(this);
      	myClass obj;
      	 ui->label_Number->setText(QString::number(obj.getNumber()));
      }
      

      In my case, I would have to create a Qlabel as private in my myDialog, and making a method to access
      my ui->label_Number, being able to update the value directly from my MainWindow button, without having to create a button inside myDialog to refresh;

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Gutoficiall
      To pass the number from MainWindow to myDialog, either create a parameter for it in the dialog constructor (if the number is only passed at construction time) or write a setter method in the dialog which accepts a number and sets its ui->label_Number from that. You do not need to export the QLabel from the dialog.

      G 1 Reply Last reply
      2
      • JonBJ JonB

        @Gutoficiall
        To pass the number from MainWindow to myDialog, either create a parameter for it in the dialog constructor (if the number is only passed at construction time) or write a setter method in the dialog which accepts a number and sets its ui->label_Number from that. You do not need to export the QLabel from the dialog.

        G Offline
        G Offline
        Gutoficiall
        wrote on last edited by
        #3

        @JonB
        Thank you take the weight off my back and help clarify, I've been thinking for hours. I was lost here...

        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