mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2025-07-06 18:55:58 +08:00
Project: Add Qt5QMLPlugin and optimize CMakeLists.
This commit is contained in:
@ -83,16 +83,13 @@ list(APPEND sources_files ${QRC_RESOURCES})
|
||||
if (WIN32)
|
||||
list(APPEND sources_files ${EXAMPLE_VERSION_RC_PATH})
|
||||
endif ()
|
||||
if (${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
||||
qt_add_executable(${PROJECT_NAME}
|
||||
MANUAL_FINALIZATION
|
||||
${sources_files}
|
||||
)
|
||||
else ()
|
||||
add_executable(${PROJECT_NAME}
|
||||
${sources_files}
|
||||
)
|
||||
endif ()
|
||||
|
||||
if (${QT_VERSION_MAJOR} LESS 6)
|
||||
include(Qt5QMLPlugin)
|
||||
endif()
|
||||
qt_add_executable(${PROJECT_NAME}
|
||||
${sources_files}
|
||||
)
|
||||
add_dependencies(${PROJECT_NAME} Script-UpdateTranslations)
|
||||
|
||||
#复制程序运行所需要的动态库
|
||||
@ -147,7 +144,6 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||
Qt${QT_VERSION_MAJOR}::Network
|
||||
fluentuiplugin
|
||||
)
|
||||
|
||||
#添加部署脚本
|
||||
if (CMAKE_BUILD_TYPE MATCHES "Release")
|
||||
if (APPLE)
|
||||
|
@ -23,4 +23,4 @@ SINGLETON(TranslateHelper)
|
||||
private:
|
||||
QQmlEngine *_engine = nullptr;
|
||||
QTranslator *_translator = nullptr;
|
||||
};
|
||||
};
|
||||
|
@ -19,18 +19,51 @@
|
||||
#include "src/helper/InitializrHelper.h"
|
||||
#include "src/helper/TranslateHelper.h"
|
||||
#include "src/helper/Network.h"
|
||||
|
||||
#include <QDirIterator>
|
||||
#ifdef FLUENTUI_BUILD_STATIC_LIB
|
||||
#if (QT_VERSION > QT_VERSION_CHECK(6, 2, 0))
|
||||
Q_IMPORT_QML_PLUGIN(FluentUIPlugin)
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0))
|
||||
#define Q_IMPORT_QML_PLUGIN(PLUGIN) \
|
||||
Q_IMPORT_PLUGIN(PLUGIN)
|
||||
extern void qml_static_register_types_FluentUI();
|
||||
#endif
|
||||
#include <FluentUI.h>
|
||||
Q_IMPORT_QML_PLUGIN(FluentUIPlugin)
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#include "app_dmp.h"
|
||||
#endif
|
||||
|
||||
void listFiles(const QString &path) {
|
||||
QDir dir(path);
|
||||
// 设置过滤器以包括目录和文件,排除符号链接
|
||||
dir.setFilter(QDir::Files | QDir::Dirs);
|
||||
// 获取目录和文件信息列表
|
||||
QFileInfoList list = dir.entryInfoList();
|
||||
|
||||
for (const QFileInfo &fileInfo : list) {
|
||||
if (fileInfo.isDir()) {
|
||||
// 如果是目录,则递归调用listFiles
|
||||
listFiles(fileInfo.absoluteFilePath());
|
||||
} else {
|
||||
// 输出文件名称
|
||||
qDebug() << "文件名: " << fileInfo.fileName();
|
||||
QFile file(fileInfo.absoluteFilePath());
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
continue;
|
||||
|
||||
QTextStream in(&file);
|
||||
// 输出文件内容
|
||||
qDebug() << "文件内容: ";
|
||||
while (!in.atEnd()) {
|
||||
QString line = in.readLine();
|
||||
qDebug() << line;
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *uri = "example";
|
||||
@ -78,17 +111,16 @@ int main(int argc, char *argv[])
|
||||
qmlRegisterType<NetworkParams>(uri,major,minor,"NetworkParams");
|
||||
qmlRegisterType<OpenGLItem>(uri,major,minor,"OpenGLItem");
|
||||
qmlRegisterUncreatableMetaObject(NetworkType::staticMetaObject, uri, major, minor, "NetworkType", "Access to enums & flags only");
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
#ifdef FLUENTUI_BUILD_STATIC_LIB
|
||||
qml_static_register_types_FluentUI();
|
||||
#endif
|
||||
TranslateHelper::getInstance()->init(&engine);
|
||||
engine.rootContext()->setContextProperty("AppInfo",AppInfo::getInstance());
|
||||
engine.rootContext()->setContextProperty("SettingsHelper",SettingsHelper::getInstance());
|
||||
engine.rootContext()->setContextProperty("InitializrHelper",InitializrHelper::getInstance());
|
||||
engine.rootContext()->setContextProperty("TranslateHelper",TranslateHelper::getInstance());
|
||||
engine.rootContext()->setContextProperty("Network",Network::getInstance());
|
||||
#ifdef FLUENTUI_BUILD_STATIC_LIB
|
||||
FluentUI::getInstance()->registerTypes(&engine);
|
||||
#endif
|
||||
const QUrl url(QStringLiteral("qrc:/example/qml/App.qml"));
|
||||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
|
||||
&app, [url](QObject *obj, const QUrl &objUrl) {
|
||||
|
Reference in New Issue
Block a user