我有這樣的片斷代碼:QT具體實施
#include <QApplication>
#include <QFont>
#include <QLCDNumber>
#include <QPushButton>
#include <QSlider>
#include <QVBoxLayout>
#include <QWidget>
class MyWidget : public QWidget
{
public:
MyWidget(QWidget *parent = 0);
};
MyWidget::MyWidget(QWidget *parent)
: QWidget(parent)
{
QPushButton *quit = new QPushButton(tr("Quit"));
quit->setFont(QFont("Times", 18, QFont::Bold));
QLCDNumber *lcd = new QLCDNumber(3);
lcd->setSegmentStyle(QLCDNumber::Flat);
QSlider *slider = new QSlider(Qt::Horizontal);
slider->setRange(0, 999);
slider->setValue(0);
connect(quit, SIGNAL(clicked()), qApp, SLOT(quit()));
connect(slider, SIGNAL(valueChanged(int)),
lcd, SLOT(display(int)))
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(quit);
layout->addWidget(lcd);
layout->addWidget(slider);
setLayout(layout);
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MyWidget widget;
widget.show();
return app.exec();
}
當我到達區間的最大值,我要退出,我怎麼能實現這個with signals and slots
,在此先感謝
在這一行中,我有兩個問題:價值==滑塊 - >最大(),滑塊沒有在範圍內定義,第二,即使我把它改爲999後,它不起作用,請問你能解釋爲什麼? – wantSTUDY 2010-07-15 16:53:01
是的,你需要先在你的課堂上預定義「滑塊」。在'public'字和代碼生效之後,在你的類中添加'QSlider * slider';'slider = new QSlider(Qt :: Horizontal);'; – mosg 2010-07-15 18:38:39