头文件:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class QLabel;
class QToolButton;
class QDateTime;
class Match;
class Check;
class Setting;
class Data;
class QGridLayout;
class QHBoxLayout;
class QVBoxLayout;
namespace Ui {
    class MainWindow;
}
class MainWindow : public QMainWindow {
    Q_OBJECT
public:
    MainWindow();
private slots:
    void goMatch();
    void goCheck();
    void goSetting();
    void goData();
    //当槽作为信号的响应函数执行时忽略返回值,作为普通函数时就像普通一样使用。
private:
    void createToolButton();
    void createLabel();
    void createDateTime();
    void createLayout();
    QLabel *timeLabel;
    QDateTime *dateTime;
    QToolButton *matchButton;
    QToolButton *checkButton;
    QToolButton *settingButton;
    QToolButton *dataButton;
    QToolButton *closeButton;
    QLabel *matchLabel;
    QLabel *checkLabel;
    QLabel *settingLabel;
    QLabel *dataLabel;
    QLabel *closeLabel;
};
#endif // MAINWINDOW_H
----------------------------------------------------------------------------------------------
cpp文件:
#include <QtGui>
#include "check.h"
#include "match.h"
#include "mainwindow.h"
#include "setting.h"
#include "data.h"
MainWindow::MainWindow()
{
    createToolButton();
    createLabel();
    createLayout();
}
void MainWindow::createToolButton()
{
    matchButton = new QToolButton;
    matchButton->setIcon(QIcon(":/images/match.png"));
    connect(matchButton, SIGNAL(clicked()), this, SLOT(goMatch()));
    checkButton = new QToolButton;
    checkButton->setIcon(QIcon(":/images/check.png"));
    connect(checkButton, SIGNAL(clicked()), this, SLOT(goCheck()));
    settingButton = new QToolButton;
    settingButton->setIcon(QIcon(":/images/setting.png"));
    connect(settingButton, SIGNAL(clicked()), this, SLOT(goSetting()));
    dataButton = new QToolButton;
    dataButton->setIcon(QIcon(":/images/data.png"));
    connect(dataButton, SIGNAL(clicked()), this, SLOT(goData()));
    closeButton = new QToolButton;
    closeButton->setIcon(QIcon(":/images/close.png"));
}
void MainWindow::createLabel()
{
    matchLabel = new QLabel;
    matchLabel->setText("Match");
    checkLabel = new QLabel;
    checkLabel->setText("Check");
    settingLabel = new QLabel;
    settingLabel->setText("Setting");
    dataLabel = new QLabel;
    dataLabel->setText("Data");
    closeLabel = new QLabel;
    closeLabel->setText("Close");
}
void MainWindow::createLayout()
{
    QGridLayout *lowerLayout = new QGridLayout;
    lowerLayout->addWidget(matchButton,2,0,5,1);
    lowerLayout->addWidget(checkButton,2,1,5,1);
    lowerLayout->addWidget(dataButton,2,2);
    lowerLayout->addWidget(settingButton,4,2);
    lowerLayout->addWidget(closeButton,6,2);
    lowerLayout->addWidget(matchLabel,7,0);
    lowerLayout->addWidget(checkLabel,7,1);
    lowerLayout->addWidget(dataLabel,3,2);
    lowerLayout->addWidget(settingLabel,5,2);
    lowerLayout->addWidget(closeLabel,7,2);
    QHBoxLayout *upperLayout = new QHBoxLayout;
    upperLayout->addWidget(timeLabel);
    upperLayout->addStretch();
    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addLayout(upperLayout);
    mainLayout->addLayout(lowerLayout);
    setLayout(mainLayout);
    setWindowTitle(tr("colourmeter"));
}
void MainWindow::goMatch()
{
    Match mainwindow(this);
}
void MainWindow::goCheck()
{
   Check mainwindow(this);
}
void MainWindow::goSetting()
{
    Setting mainwindow(this);
}
void MainWindow::goData()
{
    Data mainwindow(this);
}