Skip to content

Commit

Permalink
[更新模块路径和资源设置]:对BatteryQuick模块的路径和资源设置进行了更新,以符合新的Qt模块化规范。
Browse files Browse the repository at this point in the history
- 修改了`BatteryQuick.pro`文件,将资源前缀从`/qml`更改为`/qt/qml/BatteryQuickResources`,以确保QML模块能够被正确加载。
- 在`CMakeLists.txt`中更新了`qt_add_qml_module`的`URI`参数,从`qml`更改为`BatteryQuickResources`,以匹配模块的新路径。
- 对`main.cc`文件进行了更改,更新了QML文件的加载路径,确保它指向新的资源路径。
- 在`CMakeLists.txt`中指定了Qt的版本为6.5,并设置了新的策略`QTP0001 NEW`,以适应Qt 6.5的新特性。
- 为`BatteryQuick`可执行文件添加了安装规则,确保构建后的文件可以被正确安装到指定目录。
  • Loading branch information
RealChuan committed May 28, 2024
1 parent ab2426f commit 0641d22
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion BatteryQuick/BatteryQuick.pro
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SOURCES += \
main.cc

resources.files = Main.qml
resources.prefix = /qml
resources.prefix = /qt/qml/BatteryQuickResources
RESOURCES += resources

# Additional import path used to resolve QML modules in Qt Creator's code model
Expand Down
9 changes: 8 additions & 1 deletion BatteryQuick/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ qt_add_executable(BatteryQuick main.cc)
qt_add_qml_module(
BatteryQuick
URI
qml
BatteryQuickResources
VERSION
1.0
QML_FILES
Expand All @@ -23,3 +23,10 @@ set_target_properties(
WIN32_EXECUTABLE TRUE)

target_link_libraries(BatteryQuick PRIVATE Qt6::Quick)

include(GNUInstallDirs)
install(
TARGETS BatteryQuick
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
5 changes: 2 additions & 3 deletions BatteryQuick/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ auto main(int argc, char *argv[]) -> int
QGuiApplication app(argc, argv);

QQmlApplicationEngine engine;
const QUrl url(u"qrc:/qml/Main.qml"_qs);
const QUrl url(QStringLiteral("qrc:/qt/qml/BatteryQuickResources/Main.qml"));
QObject::connect(
&engine,
&QQmlApplicationEngine::objectCreated,
&app,
[url](QObject *obj, const QUrl &objUrl) {
if ((obj == nullptr) && url == objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}
},
Qt::QueuedConnection);
engine.load(url);
Expand Down
2 changes: 2 additions & 0 deletions BubbleWindow/bubblewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ void BubbleWidget::exec()

void BubbleWidget::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event)

QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(d_ptr->pen);
Expand Down
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ project(
include(cmake/common.cmake)

find_package(
Qt6 REQUIRED
Qt6 6.5 REQUIRED
COMPONENTS Core
Widgets
Charts
Expand All @@ -21,8 +21,8 @@ find_package(
Sql
Quick)

qt_standard_project_setup(I18N_SOURCE_LANGUAGE en I18N_TRANSLATED_LANGUAGES
zh_CN)
qt_standard_project_setup(REQUIRES 6.5)
qt_policy(SET QTP0001 NEW)
# qt_standard_project_setup will set CMAKE_RUNTIME_OUTPUT_DIRECTORY, we need to
# set it back, and use EXECUTABLE_OUTPUT_PATH
unset(CMAKE_RUNTIME_OUTPUT_DIRECTORY)
Expand Down
2 changes: 2 additions & 0 deletions TreeViewModel/listview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ void ListView::onSelectionChanged(const QItemSelection &selected, const QItemSel

void ListView::onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
Q_UNUSED(bottomRight)

if (!topLeft.isValid()) {
return;
}
Expand Down
2 changes: 2 additions & 0 deletions TreeViewModel/normaltreeview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ auto NormalTreeModel::rowCount(const QModelIndex &idx) const -> int
auto NormalTreeModel::headerData(int section, Qt::Orientation orientation, int role) const
-> QVariant
{
Q_UNUSED(orientation)

switch (role) {
case Qt::TextAlignmentRole: return Qt::AlignVCenter;
case Qt::CheckStateRole: {
Expand Down
1 change: 1 addition & 0 deletions TreeViewModel/normaltreeview.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class NormalTreeModel : public BaseTreeModel
protected:
[[nodiscard]] auto columnCount(const QModelIndex &idx) const -> int override
{
Q_UNUSED(idx)
return m_headerList.size();
}
[[nodiscard]] auto headerData(int section, Qt::Orientation orientation, int role) const
Expand Down

0 comments on commit 0641d22

Please sign in to comment.