[Moved] Calculator



  • 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.



  • 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.



  • 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.



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



  • Ok. Thanx for you!



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



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



  • 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.



  • 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.



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.