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();
}


本文转自Phinecos(洞庭散人)博客园博客,原文链接:http://www.cnblogs.com/phinecos/archive/2007/04/30/733696.html,如需转载请自行联系原作者
目录
相关文章