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. [Moved] Calculator

[Moved] Calculator

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 3.6k 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.
  • M Offline
    M Offline
    Miikukka
    wrote on last edited by
    #1

    Hola!
    I'm beginner with Qt and I have some little problem. I'm trying to make very simple calculator. Just plus calculations. I know how i can set text to line edit and it goes to list widget, but I want's to plus two spinbox and set it then to list widget. @#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::on_pushButton_clicked()
    {
    ui->listWidget->addItem(ui->spinBox->text());
    }

    void MainWindow::on_pushButton_2_clicked()
    {
    ui->listWidget->clear();
    }
    @
    Well. Does someone know what command I must do to calculate like this.

    PS. Sorry my bad English, I'm Finish and very young. Try to understand my speak.

    Thanx.

    There are no stupid questions, only stupid answers.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      what about:

      @
      int a = ui->spinBox->value();
      int b = ui->spinBox2->value();
      ui->listWidget->addItem(QStrin::number(a+b));
      @

      This is basic C/C++, not Qt.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Miikukka
        wrote on last edited by
        #3

        Sorry? Do you mean something like that I'm not using Qt but C/C++?
        @#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::on_pushButton_clicked()
        {
        int a = ui->spinBox->value();
        int b = ui->spinBox_2->value();
        ui->listWidget->addItems(QStrin::number(a+b));;
        }
        @
        Should I do like this?
        Doesn't work. It's crying of QString.

        There are no stupid questions, only stupid answers.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          type error, its QString , not QStrin....
          Have a look at the docs, which functions to use.

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Miikukka
            wrote on last edited by
            #5

            Ok. Thanx for you!

            There are no stupid questions, only stupid answers.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              Miikukka
              wrote on last edited by
              #6

              Last question. Can I set maxim number to spinboxes? And how I do that?

              There are no stupid questions, only stupid answers.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #7

                Pleas eread the doc of QSpinBox. It's stated there...

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  Miikukka
                  wrote on last edited by
                  #8

                  Ok, I read it and find, but can you look this what's a problem:
                  @#include "test.h"
                  #include "ui_test.h"

                  Test::Test(QWidget *parent) :
                  QMainWindow(parent),
                  ui(new Ui::Test)
                  {
                  ui->setupUi(this);
                  }

                  Test::~Test()
                  {
                  delete ui;
                  }

                  void Test::on_pushButton_clicked()
                  {
                  int a = ui->spinBox->value();
                  int b = ui->spinBox_4->value();
                  int c = ui->spinBox_2->value();
                  int d = ui->spinBox_5->value();
                  int e = ui->spinBox_3->value();
                  int f = ui->spinBox_6->value();
                  ui->listWidget->addItem(QString::number(((((a*20+3)*5+c)*20+3)5+e-1515)+((((b20+3)*5+d)*20+3)5+f-1515)))();
                  }@
                  I wan't put operation ((((a
                  20+3)*5+c)*20+3)5+e-1515)+((((b20+3)*5+d)*20+3)*5+f-1515), but when I dot like this it said: "void value not ignored as it ought to be". I don't understand what it means so can you please help me.
                  Thanks a lot.

                  Sorry, I find a mistake.

                  There are no stupid questions, only stupid answers.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #9

                    What is the last () at the end of the line doing there on line 24?

                    By the way; I think it makes more sense to separate the calculation and the putting the value in the listwidget to two separate lines. That makes the code easier to read.

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      Miikukka
                      wrote on last edited by
                      #10

                      Yeah! Now it works! Thanx a lot. I had the last () too much and my symbian^3 qt simulator didn't work.

                      There are no stupid questions, only stupid answers.

                      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