Skip to content

Commit

Permalink
[项目重构与构建系统优化]: 对项目结构进行了重构,并优化了构建系统,提升了项目的可维护性和构建效率。
Browse files Browse the repository at this point in the history
- 更新了 `BatteryQuick` 项目的 `.pro` 文件,更改了资源文件的前缀路径。
- 在 `CMakeLists.txt` 中更新了 Qt 的版本要求,并调整了安装路径规则。
- 对 `main.cc` 文件进行了修改,更新了 QML 文件的资源路径。
- 在多个源文件中用 `std::as_const` 替换了 `qAsConst`,以提供更清晰的常量视图。
- 更新了 `LogAsynchronous` 项目的 `.pro` 文件,统一了 Qt 模块的包含,并更新了 C++ 标准至 C++17。
- 重命名了多个示例项目的目录和文件,以保持一致的命名规范。
- 更新了 `README.md` 文件,改进了文档结构,并更新了图片展示方式。
- 删除了 Ubuntu 打包脚本中的旧 DEBIAN 目录和相关脚本,并更新了构建脚本。
- 重写了 macOS 打包脚本,增加了新的 `distribution.xml`、`dmg.json` 和其他资源文件。
- 更新了 Windows 打包脚本,删除了旧的 Inno Setup 脚本,并提供了新的签名脚本。

[依赖管理与安全性增强]: 改进了项目的依赖管理,并增强了软件的安全性。

- 在 `3rdparty.pri` 文件中更新了库依赖,移除了对某些静态库的依赖,并增加了动态库的链接。
- 更新了 Qt 版本,以确保使用最新的安全修复和功能改进。

[跨平台支持与兼容性改进]: 加强了项目的跨平台支持,并改进了与不同操作系统的兼容性。

- 对 macOS、Ubuntu 和 Windows 的打包脚本进行了更新,确保软件在不同平台上都能正确构建和打包。
- 针对 macOS 系统,更新了 `build.py` 脚本,使用 `appdmg` 工具创建 DMG 镜像。
- 对 Windows 系统,提供了新的签名脚本,以增强安装包的安全性。

[示例项目与文档更新]: 更新了示例项目,并改进了相关文档,提升了用户体验和易用性。

- 更新了多个示例项目的源代码,以展示 Qt 的最新特性和最佳实践。
- 改进了 `README.md` 中的文档结构,使得文档更加清晰易懂,并更新了示例图片。
  • Loading branch information
RealChuan committed May 31, 2024
1 parent 259b83a commit b9413ba
Show file tree
Hide file tree
Showing 43 changed files with 437 additions and 535 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: 1 addition & 1 deletion Chart/datetimechart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DateTimeChart::DateTimeChartPrivate
PointList pointList = generateRandomDataPoints(5, 101);
int year = 2020;
int mouth = 1;
for (const QPointF &p : qAsConst(pointList)) {
for (const QPointF &p : std::as_const(pointList)) {
QDateTime momentInTime(QDate(year, mouth, 15), QTime());
scatterSeries->append(momentInTime.toMSecsSinceEpoch(), p.y());
lineSeries->append(momentInTime.toMSecsSinceEpoch(), p.y());
Expand Down
4 changes: 2 additions & 2 deletions FlowLayout/flowlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ auto FlowLayout::sizeHint() const -> QSize
auto FlowLayout::minimumSize() const -> QSize
{
QSize size;
for (const QLayoutItem *item : qAsConst(itemList))
for (const QLayoutItem *item : std::as_const(itemList))
size = size.expandedTo(item->minimumSize());

const QMargins margins = contentsMargins();
Expand All @@ -181,7 +181,7 @@ auto FlowLayout::doLayout(const QRect &rect, bool testOnly) const -> int
//! [9]

//! [10]
for (QLayoutItem *item : qAsConst(itemList)) {
for (QLayoutItem *item : std::as_const(itemList)) {
const QWidget *wid = item->widget();
int spaceX = horizontalSpacing();
if (spaceX == -1)
Expand Down
4 changes: 2 additions & 2 deletions FlowLayout/flowwidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void FlowWidget::setItems(const QStringList &list)
QList<LabelWidget *> widgets = findChildren<LabelWidget *>();
qDeleteAll(widgets);

for (const QString &text : qAsConst(list)) {
for (const QString &text : std::as_const(list)) {
addItem(text);
}
}
Expand All @@ -75,7 +75,7 @@ QStringList FlowWidget::items() const
{
QStringList list;
QList<LabelWidget *> widgets = findChildren<LabelWidget *>();
for (LabelWidget *widget : qAsConst(widgets)) {
for (LabelWidget *widget : std::as_const(widgets)) {
list.append(widget->text());
}
return list;
Expand Down
2 changes: 1 addition & 1 deletion GridViewModel/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void MainWindow::setupUI()

m_imageVector.clear();
auto colorNames = QColor::colorNames();
for (const QString &colorName : qAsConst(colorNames)) {
for (const QString &colorName : std::as_const(colorNames)) {
QImage image(WIDTH, WIDTH, QImage::Format_ARGB32);
image.fill(Qt::transparent);
QPainter painter(&image);
Expand Down
4 changes: 2 additions & 2 deletions ImageCarousel/imagecarousel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ auto ImageCarousel::addImage(const QString &filename) -> bool
auto ImageCarousel::addImages(const QStringList &filenames) -> int
{
int count = 0;
for (const auto &filename : qAsConst(filenames)) {
for (const auto &filename : std::as_const(filenames)) {
if (addImage(filename)) {
++count;
}
Expand All @@ -67,7 +67,7 @@ auto ImageCarousel::addImages(const QStringList &filenames) -> int

void ImageCarousel::clearImages()
{
for (auto item : qAsConst(d_ptr->items)) {
for (auto item : std::as_const(d_ptr->items)) {
scene()->removeItem(item);
delete item;
}
Expand Down
4 changes: 1 addition & 3 deletions LogAsynchronous/LogAsynchronous.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
QT += core gui concurrent

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
QT += core gui concurrent widgets

CONFIG += c++17

Expand Down
4 changes: 3 additions & 1 deletion LogAsynchronous/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ MainWindow::~MainWindow()
m_watcher.cancel();
m_watcher.waitForFinished();
}
LogAsync::instance()->stop();
qDebug() << "Stop Log!";
}

Expand All @@ -39,8 +40,9 @@ void MainWindow::testLog()
timer.start();

for (int i = 0; i < 1000; i++) {
if (!m_running)
if (!m_running) {
break;
}
qInfo() << "1234567890qwertyuiopasdfghjklzxcvbnm" << i;
QThread::msleep(1); //主界面无响应,上下文切换太快
}
Expand Down
Loading

0 comments on commit b9413ba

Please sign in to comment.