diff --git a/CMakeLists.txt b/CMakeLists.txt index b75736fb..aa11281d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/.cmake/) include(GetGitRevisionDescription) option(FLUENTUI_BUILD_EXAMPLES "Build FluentUI demo applications." ON) -option(FLUENTUI_BUILD_STATIC_LIB "Build static library." OFF) +option(FLUENTUI_BUILD_STATIC_LIB "Build static library." ON) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core) diff --git a/example/src/main.cpp b/example/src/main.cpp index 804f739e..f504b5d3 100644 --- a/example/src/main.cpp +++ b/example/src/main.cpp @@ -90,7 +90,7 @@ int main(int argc, char *argv[]) { engine.rootContext()->setContextProperty("TranslateHelper", TranslateHelper::getInstance()); engine.rootContext()->setContextProperty("Network", Network::getInstance()); #ifdef FLUENTUI_BUILD_STATIC_LIB - FluentUI::getInstance()->registerTypes(&engine); + FluentUI::registerTypes(&engine); #endif const QUrl url(QStringLiteral("qrc:/example/qml/App.qml")); QObject::connect( diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5cc51946..2b2ed970 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -145,7 +145,7 @@ endif () if (QT_VERSION VERSION_GREATER_EQUAL "6.2") #如果是Qt6.2版本以上,则使用qt_add_library,qt_add_qml_module函数添加资源文件 if (FLUENTUI_BUILD_STATIC_LIB) - set(FLUENTUI_QML_PLUGIN_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/FluentUI) + set(FLUENTUI_QML_PLUGIN_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/FluentUI) endif () qt_add_library(${PROJECT_NAME} ${LIB_TYPE}) qt_add_qml_module(${PROJECT_NAME} diff --git a/src/FluentUI.cpp b/src/FluentUI.cpp index de5569b4..8842a8e1 100644 --- a/src/FluentUI.cpp +++ b/src/FluentUI.cpp @@ -23,12 +23,14 @@ #include "qmlcustomplot/ticker.h" #include "qmlcustomplot/grid.h" +const char* FluentUI::_uri = "FluentUI"; + void FluentUI::registerTypes(QQmlEngine *engine) { initializeEngine(engine, _uri); registerTypes(_uri); } -void FluentUI::registerTypes(const char *uri) const { +void FluentUI::registerTypes(const char *uri) { #if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0)) Q_INIT_RESOURCE(fluentui); int major = _major; diff --git a/src/FluentUI.h b/src/FluentUI.h index 600e4a0a..f2a84bf0 100644 --- a/src/FluentUI.h +++ b/src/FluentUI.h @@ -2,25 +2,22 @@ #include #include -#include "singleton.h" /** * @brief The FluentUI class */ -class FluentUI : public QObject { - Q_OBJECT +class FluentUI{ public: - SINGLETON(FluentUI) - Q_DECL_EXPORT void registerTypes(QQmlEngine *engine); + static Q_DECL_EXPORT void registerTypes(QQmlEngine *engine); - void registerTypes(const char *uri) const; + static void registerTypes(const char *uri); - void initializeEngine(QQmlEngine *engine, [[maybe_unused]] const char *uri); + static void initializeEngine(QQmlEngine *engine, [[maybe_unused]] const char *uri); private: - const int _major = 1; - const int _minor = 0; - const char *_uri = "FluentUI"; + static const int _major = 1; + static const int _minor = 0; + static const char *_uri; };