Hello,
I'm new in Qt programming. I've made a simple program:
calculator.h:
#ifndef CALCULATOR_H
#define CALCULATOR_H
#include <QtGui/QWidget>
#include "ui_calculator.h"
{
Q_OBJECT
public:
~Calculator();
private:
Ui::CalculatorClass ui;
public slots:
};
#endif // CALCULATOR_H
#ifndef CALCULATOR_H
#define CALCULATOR_H
#include <QtGui/QWidget>
#include "ui_calculator.h"
class Calculator : public QWidget
{
Q_OBJECT
public:
QString text();
Calculator(QWidget *parent = 0);
~Calculator();
private:
Ui::CalculatorClass ui;
public slots:
void add_digit_0(QString &text);
};
#endif // CALCULATOR_H
To copy to clipboard, switch view to plain text mode
calculator.cpp:
#include "calculator.h"
Calculator
::Calculator(QWidget *parent
){
ui.setupUi(this);
connect( ui.button_0, SIGNAL( clicked() ), this, SLOT( add_digit_0(text) ) );
}
Calculator::~Calculator()
{
}
void Calculator
::add_digit_0(QString &text
) {
text+='0';
ui.display->setText( text );
}
#include "calculator.h"
Calculator::Calculator(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
connect( ui.button_0, SIGNAL( clicked() ), this, SLOT( add_digit_0(text) ) );
}
Calculator::~Calculator()
{
}
void Calculator::add_digit_0(QString &text)
{
text+='0';
ui.display->setText( text );
}
To copy to clipboard, switch view to plain text mode
'dispaly' is QLineEdit and 'button_0' is a QPushButton object.
Compiler shows no errors, but when I run a program nothing happens (there is no text in display unit). I tested it a thousand times and it seems that SLOT( add_digit(text) ) does not want to recieve any arguments, because when I write function like...
void Calculator::add_digit_0()
{
ui.display->setText("TEXT");
}
void Calculator::add_digit_0()
{
ui.display->setText("TEXT");
}
To copy to clipboard, switch view to plain text mode
...everything works.
Any Ideas how to make it work?
Thanks for help.
PS
Sorry for the topic name, but I have no idea what name should it be.
Bookmarks