資源簡介
用Qt編寫的一個時鐘程序,帶有ui設計~~~~~

代碼片段和文件信息
#include?“clock.h“
#include?“ui_clock.h“
Clock::Clock(QWidget?*parent)
????:?QDialog(parent)?ui(new?Ui::Clock)
{
????ui->setupUi(this);
????ui->timeEdit->setTime(QTime::currentTime());
????connect(ui->quitButtonSIGNAL(clicked())qAppSLOT(quit()));
????//connect(ui->saveButtonSIGNAL(clicked())thisSLOT(saveSettings()));
????connect(ui->comboBoxSIGNAL(currentIndexChanged(int))thisSLOT(updateFormat(int)));
????//connect(ui->comboBox?SIGNAL(currentIndexChanged(int))?this?SLOT(updateFormat(int)));
????//connect(timeEditor?SIGNAL(timeChanged(const?QTime&))?this?SLOT(changeClock(const?QTime&)));
????t?=?new?QTimer(this);
????connect(tSIGNAL(timeout())thisSLOT(updateClock()));
????t->start(1000);
}
void?Clock::updateClock()
{
????//if(ui->timeEdit->hasFocus())
?????//???return;
????ui->timeEdit->setTime(QTime::currentTime());
}
/*void?Clock::saveSettings()
{
????QDateTime?dt?=?QDateTime::currentDateTime();
????dt.setTime(ui->timeEdit->time());
????time_t?tt?=?(time_t)dt.toTime_t();
????int?r?=?stime(&tt);
????if(r)
????{
????????if(errno?==EPERM)
????????????QMessageBox::warning(this“Error““You?don‘t?have?permission?to?change?system?time.“);
????????QSettings?cfg(“./MyClock.ini“QSettings::IniFormat);
????????cfg.setValue(“Time/Format“QVariant((int)timeFormat));
????????qApp->quit();
}*/
//void?Clock::changeClock(const?QTime&?time)
//{
//????clockFace->display(time);
//}
/*void?Clock::readSettings()
{
????QSettings?cfg(“./MyClock.ini“?QSettings::IniFormat);
????//timeFormat?=?(TimeFormat)(cfg.value(“Time/Format“?0).toInt());
}*/
/*void?Clock::setComboIndex()
{
????int?index?=?ui->comboBox->currentIndex();//ui->comboBox->findData(QVariant((int)timeFormat));
????if?(index?>?0)
????{
????????//ui->comboBox->setCurrentIndex(index);
????}
}*/
void?Clock::updateFormat(int?index)
{
????//?get?current?selected?time?format
????//timeFormat?=?(TimeFormat)(ui->comboBox->itemData(index).toInt());
????setEditorFormat();
}
void??Clock::setEditorFormat()
{
????QString?formatStr?=?NULL;
????switch?(ui->comboBox->currentIndex())
????{
????case?1:
????????formatStr?=?“hh:mm?AP“;
????????break;
????case?0:
????default:
????????formatStr?=?“hh:mm:ss“;
????????break;
????}
????ui->timeEdit->setDisplayFormat(formatStr);
}
Clock::~Clock()
{
????delete?ui;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????2381??2009-12-02?16:24??clock\clock.cpp
?????文件????????735??2009-12-01?15:00??clock\clock.h
?????文件????????267??2009-12-01?14:18??clock\clock.pro
?????文件??????11141??2009-12-02?16:24??clock\clock.pro.user
?????文件???????2683??2009-12-01?14:39??clock\clock.ui
?????文件????3810822??2009-12-02?16:24??clock\debug\clock.exe
?????文件????1340636??2009-12-02?16:24??clock\debug\clock.o
?????文件????1308281??2009-12-01?15:01??clock\debug\main.o
?????文件???????2203??2009-12-01?15:01??clock\debug\moc_clock.cpp
?????文件????1318565??2009-12-01?15:01??clock\debug\moc_clock.o
?????文件????????177??2009-11-20?10:37??clock\main.cpp
?????文件???????5628??2009-12-02?16:22??clock\Makefile
?????文件???????5351??2009-12-02?16:22??clock\Makefile.Debug
?????文件???????5424??2009-12-02?16:22??clock\Makefile.Release
?????文件???????5016??2009-12-01?14:39??clock\ui_clock.h
?????目錄??????????0??2009-12-02?16:24??clock\debug
?????目錄??????????0??2009-12-02?16:20??clock\release
?????目錄??????????0??2009-12-02?16:20??clock
-----------?---------??----------?-----??----
??????????????7819310????????????????????18
評論
共有 條評論