<?xml version="1.0" encoding="UTF-8" ?>
- <ui version="4.0">
<class>Dialog</class>
- <widget class="QDialog" name="Dialog">
- <property name="geometry">
- <rect>
<x>0</x>
<y>0</y>
<width>223</width>
<height>117</height>
</rect>
</property>
- <property name="windowTitle">
<string>報時器</string>
</property>
- <widget class="QLabel" name="labelTime">
- <property name="geometry">
- <rect>
<x>40</x>
<y>30</y>
<width>151</width>
<height>20</height>
</rect>
</property>
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <property name="font">
- <font>
<family>Sans Serif</family>
<pointsize>16</pointsize>
</font>
</property>
- <property name="text">
<string>00:00:00</string>
</property>
</widget>
- <widget class="QPushButton" name="pushButtonApply">
- <property name="geometry">
- <rect>
<x>30</x>
<y>70</y>
<width>85</width>
<height>28</height>
</rect>
</property>
- <property name="text">
<string>報時(&T)</string>
</property>
</widget>
- <widget class="QPushButton" name="pushButtonClose">
- <property name="geometry">
- <rect>
<x>110</x>
<y>70</y>
<width>85</width>
<height>28</height>
</rect>
</property>
- <property name="text">
<string>結束[&Q]</string>
</property>
</widget>
</widget>
<resources />
- <connections>
- <connection>
<sender>pushButtonClose</sender>
<signal>clicked()</signal>
<receiver>Dialog</receiver>
<slot>close()</slot>
- <hints>
- <hint type="sourcelabel">
<x>152</x>
<y>83</y>
</hint>
- <hint type="destinationlabel">
<x>111</x>
<y>58</y>
</hint>
</hints>
</connection>
</connections>
</ui>
#include <QApplication>
#include "dialogimpl.h"
//
int main(int argc, char ** argv)
{
QApplication app( argc, argv );
DialogImpl win;
win.show();
// 在【Qt 設計家】指定樣板【信號/信號槽】
app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
return app.exec();
}
#ifndef DIALOGIMPL_H
#define DIALOGIMPL_H
//
#include <QDialog>
#include <QPushButton>
#include <QTime>
#include "ui_dialog.h"
//
class DialogImpl : public QDialog, public Ui::Dialog
{
Q_OBJECT
public:
DialogImpl( QWidget * parent = 0, Qt::WFlags f = 0 );
private:
QTime *myTimer;
QString myTime;
private slots:
//當按下【報時】時,依規定訂出函數名稱
void on_pushButtonApply_clicked();
};
#endif
#include "dialogimpl.h"
//
DialogImpl::DialogImpl( QWidget * parent, Qt::WFlags f) : QDialog(parent, f)
{
setupUi(this);
this->myTimer = new QTime();
this->on_pushButtonApply_clicked();
// 在【Qt 設計家】指定樣板【信號/信號槽】
QObject::connect(pushButtonApply, SLOT(clicked()), this, SLOT(this->on_pushButtonApply_clicked()));
}
//
void DialogImpl::on_pushButtonApply_clicked() {
myTime = myTimer->currentTime().toString("hh:mm:ss");
labelTime->setText(myTime);
}