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

Sum Variable Problem

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 5 Posters 2.4k Views 2 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.
  • m.sueM Offline
    m.sueM Offline
    m.sue
    wrote on last edited by m.sue
    #2

    Hi,
    setNum expects to get a number, you give it QString::number(ui->lineEdit->text()) which is a QString. And QString::number itself expects a number, you give it ui->lineEdit->text()which is a QString.
    -Michael.

    1 Reply Last reply
    2
    • BjornWB Offline
      BjornWB Offline
      BjornW
      wrote on last edited by
      #3

      What does the compiler say? It's usually a good place to start :-)

      1 Reply Last reply
      2
      • BuckwheatB Offline
        BuckwheatB Offline
        Buckwheat
        wrote on last edited by
        #4

        @Semara123 ... Welcome!

        1. I don't see you using "c" anywhere.
        2. Try using ui->label->setNum (ui->lineEdit->text ().toInt ());

        For more information on QString goto:
        http://doc.qt.io/qt-5/qstring.html

        Don't get discouraged. Qt is a large API and we all ask questions (even those of us who have been doing this for decades!) about it when we have problems. Good luck and have fun learning!

        Dave Fileccia

        S 1 Reply Last reply
        2
        • BuckwheatB Buckwheat

          @Semara123 ... Welcome!

          1. I don't see you using "c" anywhere.
          2. Try using ui->label->setNum (ui->lineEdit->text ().toInt ());

          For more information on QString goto:
          http://doc.qt.io/qt-5/qstring.html

          Don't get discouraged. Qt is a large API and we all ask questions (even those of us who have been doing this for decades!) about it when we have problems. Good luck and have fun learning!

          S Offline
          S Offline
          Semara123
          wrote on last edited by
          #5

          @Buckwheat said in Sum Variable Problem:

          ui->label->setNum (ui->lineEdit->text ().toInt ());

          i already did it as you said but nothing happened :(

          here is the code

          #include "mainwindow.h"
          #include "ui_mainwindow.h"
          MainWindow::MainWindow(QWidget *parent) :
              QMainWindow(parent),
              ui(new Ui::MainWindow)
          {
              ui->setupUi(this);
               ui->label->setNum(0);
          }
          
          MainWindow::~MainWindow()
          {
              delete ui;
          }
          
          void MainWindow::on_pushButton_clicked()
          {
              ui->label->setText("SempAK Naga Jantan :v");
          }
          
          
          
          void MainWindow::on_pushButton_2_clicked()
          {
              int a,b,c;
              a= 2;
              b= 2;
              c=a+b;
          
              //QString hasil = "";
              ui->label->setNum (ui->lineEdit->text().toInt());
              //ui->label->text().toInt();
          }
          
          

          Sorry to bother you T_T

          and sorry for my bad english

          1 Reply Last reply
          0
          • m.sueM Offline
            m.sueM Offline
            m.sue
            wrote on last edited by
            #6

            Hi,
            so what would you want in ui->label? The value of c, then just write ui->label->setNum(c).
            -Michael.

            1 Reply Last reply
            1
            • BuckwheatB Offline
              BuckwheatB Offline
              Buckwheat
              wrote on last edited by
              #7

              @m-sue ... If that is the intent! Otherwise you are just adding a number for the sake of adding a number! And to top it off, it is a local variable so the compiler will most likely throw it away during optimization

              Dave Fileccia

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Semara123
                wrote on last edited by Semara123
                #8

                well now i already found the solution i forgot to delete this

                case 2: _t->on_label_windowIconTextChanged((*reinterpret_cast< const QString(*)>(_a[1]))); break;
                
                in moc_mainwindow.cpp 
                

                now everything runs normally

                thank you everybody for helping me to fix this problem :D

                mrjjM 1 Reply Last reply
                0
                • S Semara123

                  well now i already found the solution i forgot to delete this

                  case 2: _t->on_label_windowIconTextChanged((*reinterpret_cast< const QString(*)>(_a[1]))); break;
                  
                  in moc_mainwindow.cpp 
                  

                  now everything runs normally

                  thank you everybody for helping me to fix this problem :D

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  @Semara123 said in Sum Variable Problem:

                  moc_mainwindow.cpp

                  This is a generated file so running qmake will recreate it.
                  So hopefully it wont come back :)

                  1 Reply Last reply
                  3
                  • BuckwheatB Offline
                    BuckwheatB Offline
                    Buckwheat
                    wrote on last edited by
                    #10

                    @Semara123 ... you are manually editing your moc_ file? Wow! Ballsy! I just let the qmake regen it for me after I change my code. :D

                    Dave Fileccia

                    S 1 Reply Last reply
                    0
                    • BuckwheatB Buckwheat

                      @Semara123 ... you are manually editing your moc_ file? Wow! Ballsy! I just let the qmake regen it for me after I change my code. :D

                      S Offline
                      S Offline
                      Semara123
                      wrote on last edited by
                      #11

                      @Buckwheat said in Sum Variable Problem:

                      @Semara123 ... you are manually editing your moc_ file? Wow! Ballsy! I just let the qmake regen it for me after I change my code. :D

                      LOL i think i didnt do anything :v, but i want to say thanks to you for helping me :D and thanks for other people :D

                      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