qt_demoe/third/qcustomplotdemo/main.cpp

73 lines
2.0 KiB
C++

#pragma execution_character_set("utf-8")
#include "frmmain.h"
#include <QApplication>
#include <QTextCodec>
#include <QFontDatabase>
#include <QTime>
#include <QDebug>
int main(int argc, char *argv[])
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
QApplication::setAttribute(Qt::AA_Use96Dpi);
#endif
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
#endif
QApplication a(argc, argv);
QFont font;
#ifdef Q_OS_WASM
QString fontFile = ":/font/DroidSansFallback.ttf";
QString fontName = "Droid Sans Fallback";
//判断图形字体是否存在,不存在则加入
QFontDatabase fontDb;
if (!fontDb.families().contains(fontName)) {
int fontId = fontDb.addApplicationFont(fontFile);
QStringList listName = fontDb.applicationFontFamilies(fontId);
if (listName.count() == 0) {
qDebug() << QString("load %1 error").arg(fontName);
}
}
//再次判断是否包含字体名称防止加载失败
if (fontDb.families().contains(fontName)) {
font = QFont(fontName);
#if (QT_VERSION >= QT_VERSION_CHECK(4,8,0))
font.setHintingPreference(QFont::PreferNoHinting);
#endif
}
#else
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
#endif
a.setFont(font);
#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
//初始化随机数种子
QTime t = QTime::currentTime();
srand(t.msec() + t.second() * 1000);
frmMain w;
w.setWindowTitle("qcustomplot示例 (QQ: 517216493 WX: feiyangqingyun)");
w.resize(1000, 650);
w.show();
return a.exec();
}