quick demo: a little improvement

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2023-01-15 14:34:14 +08:00
parent 5e7ddb1864
commit 139d5a41df
7 changed files with 28 additions and 14 deletions

View File

@ -75,15 +75,15 @@ if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
endif() endif()
if(NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY) if(NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
endif() endif()
if(NOT DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY) if(NOT DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
endif() endif()
if(NOT DEFINED CMAKE_ARCHIVE_OUTPUT_DIRECTORY) if(NOT DEFINED CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
endif() endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON)
@ -139,6 +139,13 @@ if(MSVC)
endif() endif()
endif() endif()
if(NOT DEFINED QML_IMPORT_PATH)
set(QML_IMPORT_PATH)
endif()
list(APPEND QML_IMPORT_PATH "${PROJECT_BINARY_DIR}/qml")
list(REMOVE_DUPLICATES QML_IMPORT_PATH)
set(QML_IMPORT_PATH ${QML_IMPORT_PATH} CACHE STRING "Qt Creator extra QML import paths" FORCE)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Gui) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Gui)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui)

View File

@ -51,9 +51,9 @@ add_executable(Quick ${SOURCES})
if(${QT_VERSION} VERSION_GREATER_EQUAL 6.2) if(${QT_VERSION} VERSION_GREATER_EQUAL 6.2)
set(QML_SOURCES set(QML_SOURCES
"Window.qml" "qml/Window.qml"
"ApplicationWindow.qml" "qml/ApplicationWindow.qml"
"HomePage.qml" "qml/HomePage.qml"
) )
set_source_files_properties(${QML_SOURCES} set_source_files_properties(${QML_SOURCES}
PROPERTIES QT_DISCARD_FILE_CONTENTS TRUE PROPERTIES QT_DISCARD_FILE_CONTENTS TRUE
@ -62,7 +62,9 @@ if(${QT_VERSION} VERSION_GREATER_EQUAL 6.2)
URI Demo URI Demo
VERSION 1.0 VERSION 1.0
IMPORT_PATH "${PROJECT_BINARY_DIR}/qml" IMPORT_PATH "${PROJECT_BINARY_DIR}/qml"
OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/qml/Demo"
RESOURCE_PREFIX "/" RESOURCE_PREFIX "/"
NO_RESOURCE_TARGET_PATH
IMPORTS IMPORTS
QtQuick/auto QtQuick/auto
DEPENDENCIES DEPENDENCIES
@ -72,7 +74,7 @@ if(${QT_VERSION} VERSION_GREATER_EQUAL 6.2)
) )
qt_add_resources(Quick resources qt_add_resources(Quick resources
PREFIX PREFIX
"/Demo" "/"
FILES FILES
"images/microsoft.svg" "images/microsoft.svg"
) )

View File

@ -103,6 +103,11 @@ int main(int argc, char *argv[])
}()); }());
} }
// Enable some helpful debugging messages.
if (!qEnvironmentVariableIsSet("QML_IMPORT_TRACE")) {
qputenv("QML_IMPORT_TRACE", FRAMELESSHELPER_BYTEARRAY_LITERAL("1"));
}
const auto engine = std::make_unique<QQmlApplicationEngine>(); const auto engine = std::make_unique<QQmlApplicationEngine>();
engine->rootContext()->setContextProperty( engine->rootContext()->setContextProperty(
@ -121,7 +126,7 @@ int main(int argc, char *argv[])
#endif #endif
#if !QMLTC_ENABLED #if !QMLTC_ENABLED
const QUrl mainUrl(FRAMELESSHELPER_STRING_LITERAL("qrc:///Demo/HomePage.qml")); const QUrl mainUrl(FRAMELESSHELPER_STRING_LITERAL("qrc:///qml/HomePage.qml"));
#endif #endif
#if (QT_VERSION >= QT_VERSION_CHECK(6, 4, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(6, 4, 0))

View File

@ -105,7 +105,7 @@ FramelessApplicationWindow {
left: parent.left left: parent.left
right: parent.right right: parent.right
} }
windowIcon: "qrc:///Demo/images/microsoft.svg" windowIcon: "qrc:///images/microsoft.svg"
windowIconVisible: true windowIconVisible: true
} }
} }

View File

@ -105,7 +105,7 @@ FramelessWindow {
left: parent.left left: parent.left
right: parent.right right: parent.right
} }
windowIcon: "qrc:///Demo/images/microsoft.svg" windowIcon: "qrc:///images/microsoft.svg"
windowIconVisible: true windowIconVisible: true
} }
} }

View File

@ -1,8 +1,8 @@
<RCC> <RCC>
<qresource prefix="/Demo"> <qresource prefix="/">
<file>images/microsoft.svg</file> <file>images/microsoft.svg</file>
<file>Window.qml</file> <file>qml/Window.qml</file>
<file>ApplicationWindow.qml</file> <file>qml/ApplicationWindow.qml</file>
<file>HomePage.qml</file> <file>qml/HomePage.qml</file>
</qresource> </qresource>
</RCC> </RCC>