本篇内容介绍了“Qt通用方法及类库有哪些”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
//初始化数据库 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); }
“Qt通用方法及类库有哪些”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。