Qt Creator中创建一个简单应用界面,显示一个spinbox、一个silder,一个TextEdit,textEidt中显示date。
#include "mainwindow.h"
#include <QApplication>
#include <QHBoxLayout>
#include <QPushButton>
#include<QSlider>
#include <QSpinBox>
#include <QDateTime>
#include <QTextEdit>
#include <QTime>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *window = new QWidget();
window->setWindowTitle("Enter your age:");
QSlider *slider = new QSlider(Qt::Horizontal);
slider->setRange(0,100);
QSpinBox *spinBox = new QSpinBox();
spinBox->setRange(0,100);
QObject::connect(spinBox,SIGNAL(valueChanged(int)),slider,SLOT(setValue(int)));
QObject::connect(slider,SIGNAL(valueChanged(int)),spinBox,SLOT(setValue(int)));
spinBox->setValue(5);
QDate *date = new QDate(2015,8,10);
QTextEdit *text = new QTextEdit();
text->setText(date->toString());
QHBoxLayout *layout = new QHBoxLayout();
layout->addWidget(spinBox);
layout->addWidget(slider);
layout->addWidget(text);
window->setLayout(layout);
window->show();
return app.exec();
}