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(20204422));
    slider
->setGeometry(QRect(902016021));
    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();
}

posted on 2007-04-30 21:45  Phinecos(洞庭散人)  阅读(471)  评论(0编辑  收藏  举报

导航