1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| class MyWidget : public QWidget
{
public:
MyWidget(QWidget *parent = 0);
};
class SigMan: public QObject
{
Q_OBJECT
private:
int value;
public:
SigMan(int val=0);
signals:
void valueChanged(int);
public slots:
void setValue(int);
};
SigMan::SigMan(int n):
QObject()
{
value=n;
}
void SigMan::setValue(int n)
{
value=n;
emit valueChanged(value);
}
MyWidget::MyWidget(QWidget *parent)
: QWidget(parent)
{
QSlider *lcd = new QSlider(Qt::Horizontal);
lcd->setRange(0, 99);
lcd->setValue(20);
QSlider *slider = new QSlider(Qt::Horizontal);
slider->setRange(0, 99);
slider->setValue(0);
QSpinBox *qsb= new QSpinBox();
qsb->setRange(0,99);
QLCDNumber *nb=new QLCDNumber;
SigMan *s=new SigMan;
connect(slider,SIGNAL(valueChanged(int)),s,SLOT(setValue(int)));
connect(lcd,SIGNAL(valueChanged(int)),s,SLOT(setValue(int)));
connect(qsb,SIGNAL(valueChanged(int)),s,SLOT(setValue(int)));
connect(s,SIGNAL(valueChanged(int)),slider,SLOT(setValue(int)));
connect(s,SIGNAL(valueChanged(int)),lcd,SLOT(setValue(int)));
connect(s,SIGNAL(valueChanged(int)),qsb,SLOT(setValue(int)));
connect(s,SIGNAL(valueChanged(int)),nb,SLOT(display(int)));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(lcd);
layout->addWidget(slider);
layout->addWidget(qsb);
layout->addWidget(nb);
setLayout(layout);
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MyWidget widget;
widget.show();
return app.exec();
} |
Partager