hi,
I'm trying to make a simple program that gets integers from sliders,
and compute them.
A sample of my code :
data.h
#include <QtGUI>
#include <QObject>
#ifndef DATA_H
#define DATA_H
{
Q_OBJECT
public:
public slots:
void doSum();
private:
int Z0RealSliderValue;
int ZLRealSliderValue;
};
#endif // DATA_H
#include <QtGUI>
#include <QObject>
#ifndef DATA_H
#define DATA_H
class Data : public QWidget
{
Q_OBJECT
public:
Data(QWidget *parent = 0);
public slots:
void doSum();
private:
int Z0RealSliderValue;
int ZLRealSliderValue;
QLineEdit *Product;
};
#endif // DATA_H
To copy to clipboard, switch view to plain text mode
data.cpp
#include <QtGUI>
#include "data.h"
{
Z0RealInput->setRange(0, 150);
ZLRealInput->setRange(0, 150);
Z0RealSliderValue = Z0RealInput->value();
ZLRealSliderValue = ZLRealInput->value();
Product->setReadOnly(true);
connect(Plot, SIGNAL(clicked()), this, SLOT(doSum()));
//layout etc etc
....
}
void Data::doSum()
{
int Sum = 0;
Sum = ZLRealSliderValue + Z0RealSliderValue;
Product
->setText
(QString::number(Sum
));
}
#include <QtGUI>
#include "data.h"
Data::Data(QWidget *parent)
{
QSlider *Z0RealInput = new QSlider(Qt::Horizontal, this);
Z0RealInput->setRange(0, 150);
QSlider *ZLRealInput = new QSlider(Qt::Horizontal, this);
ZLRealInput->setRange(0, 150);
Z0RealSliderValue = Z0RealInput->value();
ZLRealSliderValue = ZLRealInput->value();
Product = new QLineEdit("Sum");
Product->setReadOnly(true);
QPushButton *Plot = new QPushButton(tr("Plot"),this);
connect(Plot, SIGNAL(clicked()), this, SLOT(doSum()));
//layout etc etc
....
}
void Data::doSum()
{
int Sum = 0;
Sum = ZLRealSliderValue + Z0RealSliderValue;
Product->setText(QString::number(Sum));
}
To copy to clipboard, switch view to plain text mode
It kept returning 0.
I have tried to change setting the lineedit text with a constant string, and it worked,
so I assume there is nothing wrong with the connection.
Is it how I retrieve the value which make the code not working?
Thanks in advance.
Bookmarks