zhuzichu520 / FluentUI

FluentUI for QML
MIT License
3.48k stars 456 forks source link

组件注册之惑 #479

Closed yanhuacuo closed 6 months ago

yanhuacuo commented 6 months ago

首先,感谢作者的项目,这个框架确实非常漂亮。 下面,讲一下初上手时的困扰:组件应当如何注册?

下面,谨以 SettingsHelper 与 TranslateHelper 组件的注册困扰说明。

一、FluentUI Initializr 初始化的结构与 example 不同。

初始化程序: testApp

main.cpp 对同级目录下文件的引用方式,是这样的:

#include "Version.h"
#include "AppInfo.h"
#include "helper/Log.h"
#include "src/component/CircularReveal.h"
#include "src/component/FileWatcher.h"
#include "src/component/FpsItem.h"
#include "src/helper/SettingsHelper.h"
#include "src/helper/InitializrHelper.h"
#include "src/helper/TranslateHelper.h"
#include "src/helper/Network.h"

而 testApp ,则是 qml 文件与 cpp 文件混在一块儿,所以,仿照 example 试图引入上述 cpp 及 h 文件时,在 testApp 的 main.cpp 中写成了这样:

#include "Version.h"
#include "AppInfo.h"
#include "helper/Log.h"
#include "./component/CircularReveal.h"
#include "./component/FileWatcher.h"
#include "./component/FpsItem.h"
#include "./helper/SettingsHelper.h"
#include "./helper/InitializrHelper.h"
#include "./helper/TranslateHelper.h"
#include "./helper/Network.h"

为了一步步仿写测试,到这里编译是正常的,文件寻址也都没问题,当然上述文件都是从 example 的源文件或编译物(比如 Version.h)中取出来的,不涉及程序名或其它绝对地址。

如图所示,当这样一句被添加后,QtCreator 能识别出 SettingsHelper 组件,但是编译会报错:

提示:..\myQML\testApp\src\main.cpp:30: error: undefined reference to 'SettingsHelper::init(char**)'

2024-04-04_032043

yanhuacuo commented 6 months ago

您的 example 中展示的特性,解决了许多 Qt 用户一直以来的痛点。但是 example 有着非常复杂的文件引用关系,是否考虑 FluentUI Initializr 初始化的 testApp 里预置上这些特性呢?

比如,保留「主题设置」与「托盘系统」,预置「CircularReveal」动画效果与界面布局?

2024-04-04_033221

yanhuacuo commented 6 months ago

CPP 文件添加到 cmakelists.txt 中已解决