zoukankan      html  css  js  c++  java
  • Qt通用方法及类库2

    函数名

    	//初始化数据库
        static void initDb(const QString &dbName);
        //初始化文件,不存在则拷贝
        static void initFile(const QString &sourceName, const QString &targetName);
    
        //新建目录
        static void newDir(const QString &dirName);
    
        //写入消息到额外的的消息日志文件
        static void writeInfo(const QString &info, bool needWrite = false, const QString &filePath = "log");
        static void writeError(const QString &info, bool needWrite = false, const QString &filePath = "log");
    
        //设置无边框窗体
        static void setFramelessForm(QWidget *widgetMain, QWidget *widgetTitle, QLabel *labIco, QPushButton *btnClose, bool tool = true);
    
    

    函数体

    void QUIHelper::initDb(const QString &dbName)
    {
        initFile(QString(":/%1.db").arg(appName()), dbName);
    }
    
    void QUIHelper::initFile(const QString &sourceName, const QString &targetName)
    {
        //判断文件是否存在,不存在则从资源文件复制出来
        QFile file(targetName);
        if (!file.exists() || file.size() == 0) {
            file.remove();
            QUIHelper::copyFile(sourceName, targetName);
        }
    }
    
    void QUIHelper::newDir(const QString &dirName)
    {
        QString strDir = dirName;
    
        //如果路径中包含斜杠字符则说明是绝对路径
        //linux系统路径字符带有 /  windows系统 路径字符带有 :/
        if (!strDir.startsWith("/") && !strDir.contains(":/")) {
            strDir = QString("%1/%2").arg(QUIHelper::appPath()).arg(strDir);
        }
    
        QDir dir(strDir);
        if (!dir.exists()) {
            dir.mkpath(strDir);
        }
    }
    
    void QUIHelper::writeInfo(const QString &info, bool needWrite, const QString &filePath)
    {
        if (!needWrite) {
            return;
        }
    
        QString fileName = QString("%1/%2/%3_runinfo_%4.txt").arg(QUIHelper::appPath())
                           .arg(filePath).arg(QUIHelper::appName()).arg(QDate::currentDate().toString("yyyyMM"));
    
        QFile file(fileName);
        file.open(QIODevice::WriteOnly | QIODevice::Append | QFile::Text);
        QTextStream stream(&file);
        stream << DATETIME << "  " << info << NEWLINE;
        file.close();
    }
    
    void QUIHelper::writeError(const QString &info, bool needWrite, const QString &filePath)
    {
        if (!needWrite) {
            return;
        }
    
        QString fileName = QString("%1/%2/%3_runerror_%4.txt").arg(QUIHelper::appPath())
                           .arg(filePath).arg(QUIHelper::appName()).arg(QDate::currentDate().toString("yyyyMM"));
    
        QFile file(fileName);
        file.open(QIODevice::WriteOnly | QIODevice::Append | QFile::Text);
        QTextStream stream(&file);
        stream << DATETIME << "  " << info << NEWLINE;
        file.close();
    }
    
    void QUIHelper::setFramelessForm(QWidget *widgetMain, QWidget *widgetTitle, QLabel *labIco, QPushButton *btnClose, bool tool)
    {
        labIco->setFixedWidth(TitleMinSize);
        btnClose->setFixedWidth(TitleMinSize);
        widgetTitle->setFixedHeight(TitleMinSize);
        widgetTitle->setProperty("form", "title");
    
        widgetMain->setProperty("form", true);
        widgetMain->setProperty("canMove", true);
        if (tool) {
            widgetMain->setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint);
        } else {
            widgetMain->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint);
        }
        IconHelper::Instance()->setIcon(labIco, QUIConfig::IconMain, QUIConfig::FontSize + 2);
        IconHelper::Instance()->setIcon(btnClose, QUIConfig::IconClose, QUIConfig::FontSize);
    }
    
  • 相关阅读:
    jquery获取tr并更改tr内容
    jquery获取元素索引值index()
    禁止apache显示目录索引 apache禁止列目录
    mysql启动错误之mysql启动报1067错误如何解决
    Expo大作战(四)--快速用expo构建一个app,expo中的关键术语
    Expo大作战(三)--针对已经开发过react native项目开发人员有针对性的介绍了expo,expo的局限性,开发时项目选型注意点等
    Expo大作战(二)--expo的生命周期,expo社区交流方式,expo学习必备资源,开发使用expo时关注的一些问题
    Expo大作战(一)--什么是expo,如何安装expo clinet和xde,xde如何使用
    Linux(CentOS)之-性能监控
    [转]winform程序textbox滚动条保持在最下面 内容不闪烁
  • 原文地址:https://www.cnblogs.com/feiyangqingyun/p/12732098.html
Copyright © 2011-2022 走看看