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. Math with Qt

Math with Qt

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 929 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.
  • AbderaoufA Offline
    AbderaoufA Offline
    Abderaouf
    wrote on last edited by koahnig
    #1

    Gents;

    I have been working on adding two numbers using 2 Qlinedits and displaying the result on a Qlabel using a Qpushbutton. Once launched the .exe file crashes and shows no result: please find below my code for review, your advices are welcome.

    Cheers.

    my .h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <QSpinBox>
    #include <QLabel>
    #include <QLineEdit>
    
    namespace Ui {
    class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();
    
        void valueChanged (QString resultat);
    
    private slots:
        void on_pushButton_clicked();
    
    private:
        Ui::MainWindow *ui;
    QLineEdit *Input1;
    QLineEdit *Input2;
    QLabel *resultat;
    };
    
    #endif // MAINWINDOW_H
    

    my .cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::valueChanged(QString)
    {
    
        ui->resultat->setText(QString::number(Input1->text().toInt() + Input2->text().toInt()));
    
    }
    void MainWindow::on_pushButton_clicked()
    {
       valueChanged("resultat");
    }
    
    K raven-worxR 2 Replies Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! Input1 and Input2 point to nothing.

      1 Reply Last reply
      4
      • AbderaoufA Abderaouf

        Gents;

        I have been working on adding two numbers using 2 Qlinedits and displaying the result on a Qlabel using a Qpushbutton. Once launched the .exe file crashes and shows no result: please find below my code for review, your advices are welcome.

        Cheers.

        my .h

        #ifndef MAINWINDOW_H
        #define MAINWINDOW_H
        
        #include <QMainWindow>
        #include <QSpinBox>
        #include <QLabel>
        #include <QLineEdit>
        
        namespace Ui {
        class MainWindow;
        }
        
        class MainWindow : public QMainWindow
        {
            Q_OBJECT
        
        public:
            explicit MainWindow(QWidget *parent = 0);
            ~MainWindow();
        
            void valueChanged (QString resultat);
        
        private slots:
            void on_pushButton_clicked();
        
        private:
            Ui::MainWindow *ui;
        QLineEdit *Input1;
        QLineEdit *Input2;
        QLabel *resultat;
        };
        
        #endif // MAINWINDOW_H
        

        my .cpp

        #include "mainwindow.h"
        #include "ui_mainwindow.h"
        
        MainWindow::MainWindow(QWidget *parent) :
            QMainWindow(parent),
            ui(new Ui::MainWindow)
        {
            ui->setupUi(this);
        }
        
        MainWindow::~MainWindow()
        {
            delete ui;
        }
        
        void MainWindow::valueChanged(QString)
        {
        
            ui->resultat->setText(QString::number(Input1->text().toInt() + Input2->text().toInt()));
        
        }
        void MainWindow::on_pushButton_clicked()
        {
           valueChanged("resultat");
        }
        
        K Offline
        K Offline
        koahnig
        wrote on last edited by
        #3

        @Abderaouf

        Added code tags to your post.
        Wieland was faster to answer

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply
        1
        • AbderaoufA Abderaouf

          Gents;

          I have been working on adding two numbers using 2 Qlinedits and displaying the result on a Qlabel using a Qpushbutton. Once launched the .exe file crashes and shows no result: please find below my code for review, your advices are welcome.

          Cheers.

          my .h

          #ifndef MAINWINDOW_H
          #define MAINWINDOW_H
          
          #include <QMainWindow>
          #include <QSpinBox>
          #include <QLabel>
          #include <QLineEdit>
          
          namespace Ui {
          class MainWindow;
          }
          
          class MainWindow : public QMainWindow
          {
              Q_OBJECT
          
          public:
              explicit MainWindow(QWidget *parent = 0);
              ~MainWindow();
          
              void valueChanged (QString resultat);
          
          private slots:
              void on_pushButton_clicked();
          
          private:
              Ui::MainWindow *ui;
          QLineEdit *Input1;
          QLineEdit *Input2;
          QLabel *resultat;
          };
          
          #endif // MAINWINDOW_H
          

          my .cpp

          #include "mainwindow.h"
          #include "ui_mainwindow.h"
          
          MainWindow::MainWindow(QWidget *parent) :
              QMainWindow(parent),
              ui(new Ui::MainWindow)
          {
              ui->setupUi(this);
          }
          
          MainWindow::~MainWindow()
          {
              delete ui;
          }
          
          void MainWindow::valueChanged(QString)
          {
          
              ui->resultat->setText(QString::number(Input1->text().toInt() + Input2->text().toInt()));
          
          }
          void MainWindow::on_pushButton_clicked()
          {
             valueChanged("resultat");
          }
          
          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @Abderaouf
          the variables Input1 and Input2 are never initialized, but you are accessing them.
          I guess you want the input fields from your ui file no?
          You should access them with ui->Input1

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          3
          • AbderaoufA Offline
            AbderaoufA Offline
            Abderaouf
            wrote on last edited by Abderaouf
            #5

            Thank you guys and lady. That was reallly helpful.

            1 Reply Last reply
            1

            • Login

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