forked from feiyangqingyun/QWidgetDemo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6cb47c6
commit 534c165
Showing
16 changed files
with
908 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#pragma execution_character_set("utf-8") | ||
|
||
#include "frmsavelog.h" | ||
#include "ui_frmsavelog.h" | ||
#include "savelog.h" | ||
#include "qdatetime.h" | ||
#include "qtimer.h" | ||
#include "qdebug.h" | ||
|
||
frmSaveLog::frmSaveLog(QWidget *parent) : QWidget(parent), ui(new Ui::frmSaveLog) | ||
{ | ||
ui->setupUi(this); | ||
this->initForm(); | ||
} | ||
|
||
frmSaveLog::~frmSaveLog() | ||
{ | ||
delete ui; | ||
} | ||
|
||
void frmSaveLog::initForm() | ||
{ | ||
timer = new QTimer(this); | ||
connect(timer, SIGNAL(timeout()), this, SLOT(append())); | ||
timer->setInterval(1000); | ||
|
||
SaveLog::Instance()->setPath(qApp->applicationDirPath()); | ||
} | ||
|
||
void frmSaveLog::append() | ||
{ | ||
QString msg = QString("当前时间: %1 测试打印输出消息").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")); | ||
ui->txtMain->append(msg); | ||
qDebug() << msg; | ||
} | ||
|
||
void frmSaveLog::on_btnDebug_clicked() | ||
{ | ||
QString msg = QString("当前时间: %1 手动插入消息").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")); | ||
ui->txtMain->append(msg); | ||
qDebug() << msg; | ||
} | ||
|
||
void frmSaveLog::on_ckTimer_stateChanged(int arg1) | ||
{ | ||
if (arg1 == 0) { | ||
timer->stop(); | ||
} else { | ||
timer->start(); | ||
} | ||
} | ||
|
||
void frmSaveLog::on_ckNet_stateChanged(int arg1) | ||
{ | ||
SaveLog::Instance()->setToNet(arg1 != 0); | ||
} | ||
|
||
void frmSaveLog::on_ckSave_stateChanged(int arg1) | ||
{ | ||
if (arg1 == 0) { | ||
SaveLog::Instance()->stop(); | ||
} else { | ||
SaveLog::Instance()->start(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#ifndef FRMSAVELOG_H | ||
#define FRMSAVELOG_H | ||
|
||
#include <QWidget> | ||
|
||
namespace Ui { | ||
class frmSaveLog; | ||
} | ||
|
||
class frmSaveLog : public QWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit frmSaveLog(QWidget *parent = 0); | ||
~frmSaveLog(); | ||
|
||
private: | ||
Ui::frmSaveLog *ui; | ||
QTimer *timer; | ||
|
||
private slots: | ||
void initForm(); | ||
void append(); | ||
void on_btnDebug_clicked(); | ||
void on_ckTimer_stateChanged(int arg1); | ||
void on_ckNet_stateChanged(int arg1); | ||
void on_ckSave_stateChanged(int arg1); | ||
|
||
}; | ||
|
||
#endif // FRMSAVELOG_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>frmSaveLog</class> | ||
<widget class="QWidget" name="frmSaveLog"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>400</width> | ||
<height>300</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Form</string> | ||
</property> | ||
<layout class="QGridLayout" name="gridLayout"> | ||
<item row="1" column="1"> | ||
<widget class="QCheckBox" name="ckTimer"> | ||
<property name="text"> | ||
<string>定时器打印消息</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="1" column="3"> | ||
<widget class="QCheckBox" name="ckSave"> | ||
<property name="text"> | ||
<string>保存日志</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="1" column="0"> | ||
<widget class="QPushButton" name="btnDebug"> | ||
<property name="sizePolicy"> | ||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> | ||
<horstretch>0</horstretch> | ||
<verstretch>0</verstretch> | ||
</sizepolicy> | ||
</property> | ||
<property name="text"> | ||
<string>手动插入消息</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="0" column="0" colspan="4"> | ||
<widget class="QTextEdit" name="txtMain"/> | ||
</item> | ||
<item row="1" column="2"> | ||
<widget class="QCheckBox" name="ckNet"> | ||
<property name="text"> | ||
<string>重定向到网络</string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma execution_character_set("utf-8") | ||
|
||
#include "frmsavelog.h" | ||
#include <QApplication> | ||
#include <QTextCodec> | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
QApplication a(argc, argv); | ||
a.setFont(QFont("Microsoft Yahei", 9)); | ||
|
||
#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0)) | ||
#if _MSC_VER | ||
QTextCodec *codec = QTextCodec::codecForName("gbk"); | ||
#else | ||
QTextCodec *codec = QTextCodec::codecForName("utf-8"); | ||
#endif | ||
QTextCodec::setCodecForLocale(codec); | ||
QTextCodec::setCodecForCStrings(codec); | ||
QTextCodec::setCodecForTr(codec); | ||
#else | ||
QTextCodec *codec = QTextCodec::codecForName("utf-8"); | ||
QTextCodec::setCodecForLocale(codec); | ||
#endif | ||
|
||
frmSaveLog w; | ||
w.setWindowTitle("输出日志文件"); | ||
w.show(); | ||
|
||
return a.exec(); | ||
} |
Oops, something went wrong.