当前位置: 首页 > news >正文

阿里巴巴网站做方案互站网怎么样

阿里巴巴网站做方案,互站网怎么样,特种作业人员证网上查询,一键制作图片之前没有考虑写日志时采用单独的线程#xff0c;而是将写日志的部分放在了主线程中实现#xff0c;后面发现当程序输出的日志信息过多#xff0c;程序长时间运行后会造成主线程的运行性能降低。故尝试创建一个单独的线程用来写日志。 此程序有一个弊端#xff0c;运行时没有…之前没有考虑写日志时采用单独的线程而是将写日志的部分放在了主线程中实现后面发现当程序输出的日志信息过多程序长时间运行后会造成主线程的运行性能降低。故尝试创建一个单独的线程用来写日志。 此程序有一个弊端运行时没有错误但存在文件没有关闭线程也不清楚结束了没望大神加以指导修改将其完善。 程序的结构如下 运行效果截图 上图是第一个界面密码和用户名为123点击进入后弹出一个对话框点击取消后原本填入的信息会被清除密码验证不通过会弹出提示框。 此项目是基于应用程序的项目以QDialog为基类含有两个ui文件分别为登录窗口和登录成功后显示的窗口登录窗口中在两个输入的行编辑器中进行设置属性plcaeholderText如下图 输入的密码显示框还需再设置属性echoMode和placeholderText属性。 直接上代码 main.cpp #include dialog.h#include QApplicationint main(int argc, char *argv[]) {if (QT_VERSION QT_VERSION_CHECK(5, 6, 0))QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);QApplication a(argc, argv);Dialog w;w.show();return a.exec(); } 主程序中添加以下代码 if (QT_VERSION QT_VERSION_CHECK(5, 6, 0))QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);是为了解决在ui界面设计的界面通过预览查看其效果正常但是运行程序时部分部件位置显示不正常的问题在以前的博文中有所记录。 dialog.h #ifndef DIALOG_H #define DIALOG_H#include QDialog #include welcomdlg.h #include writelog.hQT_BEGIN_NAMESPACE namespace Ui { class Dialog; } QT_END_NAMESPACEclass Dialog : public QDialog {Q_OBJECTpublic:Dialog(QWidget *parent nullptr);~Dialog();void checkedLoginInInfo();void outPutLogMsg(QString strInfo,QString strIndex);protected: // void closeEvent(QCloseEvent *event); signals:void signalSendLogMsg(QString strMsg);private slots:void on_enterButton_clicked();void on_cancelButton_clicked();private:Ui::Dialog *ui;WelcomDlg *m_welcomDlg;WriteLog *m_writeLog; }; #endif // DIALOG_H dialog.cpp #include dialog.h #include ui_dialog.h #include QDebug #include QMessageBox #include QDateTimeDialog::Dialog(QWidget *parent): QDialog(parent), ui(new Ui::Dialog) {ui-setupUi(this);m_welcomDlg new WelcomDlg(this);m_writeLog WriteLog::getInstance();connect(this,Dialog::signalSendLogMsg,m_writeLog,WriteLog::slot_receMsg); }Dialog::~Dialog() {delete ui; }void Dialog::checkedLoginInInfo() {QString str QString(%1 :%2(%3): ).arg(__FILE__).arg(__FUNCTION__).arg(__LINE__);outPutLogMsg(开始验证登录信息,str);QString strAccount ui-lineEditAccount-text().trimmed();QString strPassword ui-lineEditPassword-text();QString strMsg 用户名 strAccount 密码 strPassword;QString strInfo QString(%1 :%2(%3): ).arg(__FILE__).arg(__FUNCTION__).arg(__LINE__);outPutLogMsg(strMsg,strInfo);if(strAccount.compare(123) 0 strPassword.compare(123) 0)//大小写敏感的{QString str QString(%1 :%2(%3): ).arg(__FILE__).arg(__FUNCTION__).arg(__LINE__);outPutLogMsg(登录信息正确,str);accept();//隐藏模式对话框m_welcomDlg-show();}else{QString str QString(%1 :%2(%3): ).arg(__FILE__).arg(__FUNCTION__).arg(__LINE__);outPutLogMsg(登录信息输入错误,str);QMessageBox::warning(this,tr(警告),tr(用户名或密码错误请重新输入),QMessageBox::Yes);on_cancelButton_clicked();ui-lineEditAccount-setFocus();} }void Dialog::outPutLogMsg(QString strInfo,QString strIndex) {QString strTime QDateTime::currentDateTime().toString(yyyy-MM-dd: hh:mm:ss);strIndex.prepend(strTime);strIndex.append(strInfo);emit signalSendLogMsg(strIndex); }//void Dialog::closeEvent(QCloseEvent *event) //{ // QString str QString(%1 :%2(%3): ).arg(__FILE__).arg(__FUNCTION__).arg(__LINE__); // outPutLogMsg(执行关闭事件,str); // Q_UNUSED(event); // m_writeLog-closeFileThread(); //}void Dialog::on_enterButton_clicked() {checkedLoginInInfo(); }void Dialog::on_cancelButton_clicked() {ui-lineEditAccount-clear();//清空之后恢复原来的提示文字ui-lineEditPassword-clear();QString strMsg QString::number(0);strMsg strMsg.prepend(数据被清空为);QString str QString(%1 :%2(%3): ).arg(__FILE__).arg(__FUNCTION__).arg(__LINE__);outPutLogMsg(strMsg,str); } welcomdlg.h #ifndef WELCOMDLG_H #define WELCOMDLG_H#include QDialog #include writelog.hnamespace Ui { class WelcomDlg; }class WelcomDlg : public QDialog {Q_OBJECTpublic:explicit WelcomDlg(QWidget *parent nullptr);~WelcomDlg();void outPutLogMsg(QString strInfo,QString strIndex);signals:void signalSendLogMsg(QString strMsg); private:Ui::WelcomDlg *ui;WriteLog *m_writeLog; };#endif // WELCOMDLG_H welcomdlg.cpp #include welcomdlg.h #include ui_welcomdlg.h #include QDateTimeWelcomDlg::WelcomDlg(QWidget *parent) :QDialog(parent),ui(new Ui::WelcomDlg) {ui-setupUi(this);m_writeLog WriteLog::getInstance();connect(this,WelcomDlg::signalSendLogMsg,m_writeLog,WriteLog::slot_receMsg);QString str QString(%1 :%2(%3): ).arg(__FILE__).arg(__FUNCTION__).arg(__LINE__);outPutLogMsg(执行欢迎界面的构造函数!,str); }WelcomDlg::~WelcomDlg() {QString str QString(%1 :%2(%3): ).arg(__FILE__).arg(__FUNCTION__).arg(__LINE__);outPutLogMsg(执行欢迎界面的析构函数!,str);delete ui; }void WelcomDlg::outPutLogMsg(QString strInfo,QString strIndex) {QString strTime QDateTime::currentDateTime().toString(yyyy-MM-dd: hh:mm:ss);strIndex.prepend(strTime);strIndex.append(strInfo);emit signalSendLogMsg(strIndex); } writedlg.h #ifndef WRITELOG_H #define WRITELOG_H#include QObject #include QMutex #include QThread #include QQueue #include QFile #include QTextStream#define LOG_NAME /log.txtclass WriteLog : public QObject {Q_OBJECT private:explicit WriteLog(QObject *parent nullptr);void openLogFile();void writeLogInfo(); public:static WriteLog * getInstance();~WriteLog();// void closeFileThread(); signals:public slots:void slot_receMsg(QString str);void slot_threadStarted(); // void slot_threadFinished(); private:static QMutex m_mutex;static WriteLog *m_instance;QThread m_thread;QQueueQString m_queue;QFile *m_file; // QTextStream *m_textStream;//似乎不能chuang创建指针 };#endif // WRITELOG_H writedlg.cpp #include writelog.h #include QMutexLocker #include QCoreApplication #include QDateTime #include QDirQMutex WriteLog::m_mutex; WriteLog *WriteLog::m_instance nullptr; WriteLog::WriteLog(QObject *parent): QObject(parent) {//创建或打开日志文件openLogFile();this-moveToThread(m_thread);connect(m_thread,QThread::started,this,WriteLog::slot_threadStarted);connect(m_thread,QThread::finished,this,QObject::deleteLater);m_thread.start(); }void WriteLog::openLogFile() {QString logDir QCoreApplication::applicationDirPath() /log/ QDateTime::currentDateTime().toString(yyyy-MM-dd);QDir dir(logDir);if(!dir.exists()){dir.mkpath(logDir);}logDir LOG_NAME;m_file new QFile(logDir);if(!m_file-open(QFile::WriteOnly | QFile::Text |QFile::Append));{return ;} // m_textStream new QTextStream(m_file); }void WriteLog::writeLogInfo() {if(m_queue.isEmpty()){return ;}QString strMsg m_queue.front();m_queue.pop_front();QTextStream textStream(m_file);textStreamstrMsg\r\n;m_file-flush();//将缓存区数据刷新到文件中 }WriteLog *WriteLog::getInstance() {if(m_instance nullptr){QMutexLocker locker(m_mutex);m_instance new WriteLog;}return m_instance; }WriteLog::~WriteLog()//没有执行析构 {//关闭日志文件,退出线程 // QString preStr1(End:); // QString time QDateTime::currentDateTime().toString(yyyy-MM-dd); // QString preStr2(); // if(m_file ! nullptr) // { // m_file-close(); // delete m_file; // m_file nullptr; // }// m_thread.quit(); // m_thread.wait(); }//void WriteLog::closeFileThread() //{ // QString preStr1(End:); // QString time QDateTime::currentDateTime().toString(yyyy-MM-dd); // QString preStr2(); // preStr1 time preStr2 \r\n; // m_queue.push_back(preStr1); // writeLogInfo();if(m_file ! nullptr){m_file-close();delete m_file;m_file nullptr;} m_thread.requestInterruption();m_thread.quit();m_thread.wait(); //}void WriteLog::slot_receMsg(QString str) {m_queue.push_back(str);writeLogInfo(); }void WriteLog::slot_threadStarted() {QString preStr1(Begin:);QString time QDateTime::currentDateTime().toString(yyyy-MM-dd);QString preStr2();preStr1 time preStr2 \r\n;QString str QString(%1 :%2(%3): ).arg(__FILE__).arg(__FUNCTION__).arg(__LINE__);QString strTime QDateTime::currentDateTime().toString(yyyy-MM-dd: hh:mm:ss);QString info(写日志线程启动);strTime str;info.prepend(strTime);info.prepend(preStr1);m_queue.push_back(info);writeLogInfo(); }//void WriteLog::slot_threadFinished() //{qDebug()线程完成; // m_queue.push_back(写日志线程结束); // writeLogInfo(); //} 以上程序的编译环境是在qt5.13.2用的编译器为MinGW32。程序运行正常但自我感觉日志文件被打开写日志接束后没有关闭线程没有关闭自己尝试过关闭线程与文件但都无法很好的解决望大神指导。
http://www.yutouwan.com/news/69787/

相关文章:

  • 徐州网站开发信息wordpress博客无法评论
  • 模仿网站制作中国视觉设计网
  • 企业网站做静态网站还是网站解析出问题 邮件收不到了
  • 昆明网站建设加王道下拉陕西交通建设集团蓝商公司网站
  • 上街区网站建设中国核工业二三建设有限公司招聘信息
  • 想做一个静态网页网站不需要有后台数据库pc端网站做移动适配
  • 大型论坛网站建设wordpress捐
  • 网站制作公司宁波哪家好长沙公司网站高端网站建设
  • 电影院网站建设方案湖南长沙大学
  • 网站建设文化市场青岛商网站建设
  • 做网站台式还是笔记本网站机房建设方案
  • wordpress建站教程凌风广告设计哪个网站好
  • 公司做个网站常见的手机网站
  • 简述dw网站开发流程c mvc网站开发
  • 网站制作哪家大宁波seo推广哪家好
  • 销售网站建设怎么样网上商城网站开发
  • wordpress付费站内搜索网站开发需求清单
  • 网站建设界面建议菏泽网站备案拍照
  • django 做网站太原建站seo
  • 网站建设后台系统有哪些网站建设 php
  • 中国最大的建站平台成功营销的案例
  • 网站变成手机网站中国住建厅网站官网
  • 营销网站建设是什么意思重庆做网站建设的公司
  • 西部数码怎么上传网站网站这么做
  • 做网站卖酒随州网站建设学习
  • wordpress自助建站网站建设捌金手指下拉一
  • 青岛手机建站哪家好事件营销的步骤
  • 网站图片切换代码护理专业主要学什么
  • 做投标的在什么网站找信息网站开发和推广财务预算
  • 汉中市建设工程造价信息seo网站优化方案书