C++ Exercises(二)
1,
#include <QApplication>
#include <Qlabel>
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
// QLabel lbInfo("Hello,World",0);
QLabel *lbInfo = new QLabel("Hello,World",0);
// lbInfo.show();
lbInfo->show();
return app.exec();
}
2,
#include <QApplication>
#include <QPushButton>
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
// QPushButton btnOk("OK",0);
QPushButton *btnOk = new QPushButton("OK",0);
btnOk->resize(300,200);
QObject::connect(btnOk,SIGNAL(clicked()),&app,SLOT(quit()));//信号与槽联系起来
btnOk->show();
return app.exec();
}
3,
#include <QApplication>
#include <QWidget>
#include <QSlider>
#include <QSpinbox.h>
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
QWidget *centralwidget = new QWidget(0);
QSpinBox *spBox = new QSpinBox(centralwidget);
QSlider *slider = new QSlider(Qt::Horizontal,centralwidget);
spBox->setGeometry(QRect(20, 20, 44, 22));
slider->setGeometry(QRect(90, 20, 160, 21));
spBox->setRange(0,140);
slider->setRange(0,140);
QObject::connect(spBox,SIGNAL(valueChanged(int)),slider,SLOT(setValue(int)));//信号与槽联系起来
QObject::connect(slider,SIGNAL(valueChanged(int)),spBox,SLOT(setValue(int)));//信号与槽联系起来
spBox->setValue(32);
centralwidget->show();
return app.exec();
}
#include <QApplication>
#include <Qlabel>
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
// QLabel lbInfo("Hello,World",0);
QLabel *lbInfo = new QLabel("Hello,World",0);
// lbInfo.show();
lbInfo->show();
return app.exec();
}
2,
#include <QApplication>
#include <QPushButton>
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
// QPushButton btnOk("OK",0);
QPushButton *btnOk = new QPushButton("OK",0);
btnOk->resize(300,200);
QObject::connect(btnOk,SIGNAL(clicked()),&app,SLOT(quit()));//信号与槽联系起来
btnOk->show();
return app.exec();
}
3,
#include <QApplication>
#include <QWidget>
#include <QSlider>
#include <QSpinbox.h>
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
QWidget *centralwidget = new QWidget(0);
QSpinBox *spBox = new QSpinBox(centralwidget);
QSlider *slider = new QSlider(Qt::Horizontal,centralwidget);
spBox->setGeometry(QRect(20, 20, 44, 22));
slider->setGeometry(QRect(90, 20, 160, 21));
spBox->setRange(0,140);
slider->setRange(0,140);
QObject::connect(spBox,SIGNAL(valueChanged(int)),slider,SLOT(setValue(int)));//信号与槽联系起来
QObject::connect(slider,SIGNAL(valueChanged(int)),spBox,SLOT(setValue(int)));//信号与槽联系起来
spBox->setValue(32);
centralwidget->show();
return app.exec();
}
作者:洞庭散人
出处:http://phinecos.cnblogs.com/
本博客遵从Creative Commons Attribution 3.0 License,若用于非商业目的,您可以自由转载,但请保留原作者信息和文章链接URL。
posted on 2007-04-30 21:45 Phinecos(洞庭散人) 阅读(471) 评论(0) 编辑 收藏 举报