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

搭建一个网站需要什么男女直接做的视频网站

搭建一个网站需要什么,男女直接做的视频网站,欧美网站建设风格特点,西安摩高网站建设在现有Qt程序中实现可配置日志保存天数的代码示例,分为界面修改、配置存储和核心逻辑三部分: // 1. 在配置文件(如settings.h)中添加保存天数的配置项 class Settings { public:int logRetentionDays() const {return m_settings…

在现有Qt程序中实现可配置日志保存天数的代码示例,分为界面修改、配置存储和核心逻辑三部分:

// 1. 在配置文件(如settings.h)中添加保存天数的配置项
class Settings {
public:int logRetentionDays() const {return m_settings.value("Log/RetentionDays", 30).toInt(); // 默认30天}void setLogRetentionDays(int days) {m_settings.setValue("Log/RetentionDays", days);}private:QSettings m_settings;
};// 2. 在界面类头文件中添加控件声明(MainWindow.h)
class MainWindow : public QMainWindow {Q_OBJECT
public:// ... 原有声明
private slots:void onRetentionDaysChanged(int index);void checkLogCleanup();private:QComboBox *m_retentionCombo;QTimer *m_cleanupTimer;Settings m_settings;
};// 3. 界面初始化(MainWindow.cpp)
MainWindow::MainWindow(QWidget *parent): QMainWindow(parent)
{// 初始化下拉框m_retentionCombo = new QComboBox(this);m_retentionCombo->addItem("3天", 3);m_retentionCombo->addItem("7天", 7);m_retentionCombo->addItem("10天", 10);// 读取保存的值int savedDays = m_settings.logRetentionDays();int index = m_retentionCombo->findData(savedDays);m_retentionCombo->setCurrentIndex(index != -1 ? index : 0);connect(m_retentionCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),this, &MainWindow::onRetentionDaysChanged);// 初始化定时器(每天检查)m_cleanupTimer = new QTimer(this);connect(m_cleanupTimer, &QTimer::timeout, this, &MainWindow::checkLogCleanup);m_cleanupTimer->start(24 * 60 * 60 * 1000); // 24小时
}// 4. 处理配置变更
void MainWindow::onRetentionDaysChanged(int index)
{int days = m_retentionCombo->itemData(index).toInt();m_settings.setLogRetentionDays(days);checkLogCleanup(); // 可选:立即执行一次清理
}// 5. 实现日志清理核心逻辑
void MainWindow::checkLogCleanup()
{QDir logDir("logs");QDate currentDate = QDate::currentDate();int retentionDays = m_settings.logRetentionDays();foreach (const QFileInfo &fileInfo, logDir.entryInfoList(QDir::Files)) {// 从文件名解析日期(假设文件名格式为log_yyyy-MM-dd.txt)QString fileName = fileInfo.fileName();QDate fileDate = QDate::fromString(fileName.mid(4, 10), "yyyy-MM-dd");if (fileDate.isValid()) {int days = fileDate.daysTo(currentDate);if (days > retentionDays) {QFile::remove(fileInfo.absoluteFilePath());}}}
}

实现要点说明:

  1. 界面控件
  • 使用QComboBox提供3/7/10天选项
  • 使用QData关联存储实际天数值
  • 通过QSettings持久化配置
  1. 定时检查
  • 使用QTimer每日触发清理检查
  • 首次启动时立即执行一次清理
  1. 安全增强
  • 文件名日期解析需要验证有效性
  • 删除前可添加确认对话框(生产环境慎用)
  • 建议添加日志记录清理操作
  1. 扩展性
  • 可添加最小保留天数限制(如>=1)
  • 支持自定义天数(需添加QSpinBox)
  • 多线程处理大量文件删除

如果需要更完整的实现,可以添加以下优化:

// 增强版文件日期检测(同时检查文件元数据)
QDate getFileDate(const QFileInfo &fileInfo) {// 优先从文件名解析QDate date = parseDateFromFileName(fileInfo.fileName());// 文件名无效时使用修改日期if (!date.isValid()) {date = fileInfo.lastModified().date();}return date;
}// 带进度提示的清理
void MainWindow::checkLogCleanup() {QDir logDir("logs");int total = logDir.count();int processed = 0;foreach (const QFileInfo &fileInfo, logDir.entryInfoList(QDir::Files)) {// ... 清理逻辑// 更新进度emit cleanupProgress(++processed * 100 / total);QApplication::processEvents();}
}
http://www.yayakq.cn/news/804398/

相关文章:

  • 广州网站制作多少钱wordpress5.0.1编辑器
  • 无锡机关单位建设网站网站访客qq号码获取
  • 玉溪的网站建设公司网站页脚设计代码
  • 娱乐网站的特点新手怎样做网站推广
  • 装修建材网站wordpress 分类 权限
  • 什么样 个人网站 备案如何在网站上添加qq
  • 外贸网站建设评价网站开发交互原型标注图
  • 阿里云建站wordpress打开2345网址大全
  • 网站运营托管网站设计权限
  • 网络推广 SEO优化 网站建设软件外包公司开发流程
  • 长安网站建设网络推广网站建设客户怎么找
  • 白酒网站设计厦门广告设计制作公司
  • 网站开发8080无法访问此页面wordpress模板函数
  • 重庆手机网站推广报价秦皇岛建设里小区
  • 做网站优化企业注册wordpress发送邮件
  • 小程序做网站登录wordpress区块链快讯模板
  • 什么网站可以做高数罗源城乡建设网站
  • 巴士定制网站开发php做网站标题加链接
  • 客户网站回访上海网站设计制作公司
  • html做网站的原则金马国旅网站建设
  • 婚庆网站设计wap软件
  • html网站怎么做莱芜网站网站建设
  • 哪个旅游网站可以做私人定制wordpress头部导航栏
  • wordpress 添加字段深圳网站优化排名公司
  • 镇江市扬中市做网站科技管理信息网站的建设方案
  • 苏州企业网站开发网站域名使用费
  • 农业网站素材wordpress 单栏
  • 无锡市住房与城乡建设网站校友会网站建设的目的
  • 大渡口网站建设中国前十强企业
  • 惠州哪家做网站好站长工具whois查询