Skip to content

Commit

Permalink
feat/qt6 (#9)
Browse files Browse the repository at this point in the history
* feat: remove qml component version to use default

* chore: tweak map qml for qt6

* fix: disable critical log control because it may cause crash

* fix: log level for unsuccessful resolve

* chore: rename qml map file

* feat(ci): update qt version

* fix(ci): add missing modules
  • Loading branch information
Candinya authored Apr 27, 2024
1 parent b6c2683 commit aa3d4fe
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 39 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/build-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ jobs:
- name: Install Qt environment
uses: jurplel/install-qt-action@v3
with:
version: '5.15.2'
version: '6.7.0'
host: 'windows'
target: 'desktop'
arch: 'win64_msvc2019_64'
install-deps: 'true'
cache: 'true'
tools: 'tools_opensslv3_x64 tools_ifw'
modules: 'qtlocation qtpositioning'

- name: Checkout codes
uses: actions/checkout@v4
Expand Down Expand Up @@ -60,7 +61,7 @@ jobs:
- name: Win Deploy Qt
shell: cmd
run: |
call "%Qt5_DIR%\bin\qtenv2.bat"
call "%Qt6_DIR%\bin\qtenv2.bat"
for /f "delims=" %%d in ( 'vswhere.exe -latest -property installationPath' ) do @( call "%%d\VC\Auxiliary\Build\vcvars64.bat" )
chdir /d %GITHUB_WORKSPACE%\workspace\%ARCHIVE_NAME%
windeployqt --qmldir %GITHUB_WORKSPACE% --release NyaTrace.exe
Expand Down
28 changes: 14 additions & 14 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ void customMessageHandler(QtMsgType type, const QMessageLogContext &context, con

// 检查日志窗口是否开启
if (ntlw != nullptr) {
if (!ntlw->isActiveWindow()) {
// 没有开启
if (type == QtCriticalMsg) {
// 因为是 fatal 日志,所以必须让用户感知到
qDebug() << "Show log dialog to let users know";
ntlw->show();
}
}
// if (!ntlw->isActiveWindow()) {
// // 没有开启
// if (type == QtCriticalMsg) {
// // 因为是 fatal 日志,所以必须让用户感知到
// qDebug() << "Show log dialog to let users know";
// ntlw->show();
// }
// }

// 写出日志
if (printToLogsTable) {
Expand All @@ -95,12 +95,12 @@ void customMessageHandler(QtMsgType type, const QMessageLogContext &context, con
}
}

if (type == QtCriticalMsg) {
// 尝试销毁主窗口
if (ntgw != nullptr) {
delete ntgw;
}
}
// if (type == QtCriticalMsg) {
// // 尝试销毁主窗口
// if (ntgw != nullptr) {
// delete ntgw;
// }
// }
}

int main(int argc, char *argv[])
Expand Down
2 changes: 1 addition & 1 deletion nyatrace.pro
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ DEFINES += \
_WINSOCKAPI_

RESOURCES += \
tracing_map.qml
nyatrace_map.qml

RC_ICONS += \
icon.ico
Expand Down
2 changes: 1 addition & 1 deletion nyatrace_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ NyaTraceMap::NyaTraceMap(QWidget *parent) :
ui->setupUi(this);

// 初始化追踪地图 (OSM)
ui->tracingMap->setSource(QUrl("qrc:/tracing_map.qml"));
ui->tracingMap->setSource(QUrl("qrc:/nyatrace_map.qml"));
ui->tracingMap->show();
}

Expand Down
40 changes: 20 additions & 20 deletions tracing_map.qml → nyatrace_map.qml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import QtQuick 2.15
import QtLocation 5.15
import QtPositioning 5.15
import QtQuick
import QtLocation
import QtPositioning

Rectangle {
id: container
anchors.fill: parent

// 参考 https://doc.qt.io/qt-5/location-plugin-osm.html
// 参考 https://doc.qt.io/qt-6/location-plugin-osm.html
Plugin {
id: osmPlugin
name: "osm"
Expand All @@ -23,13 +23,13 @@ Rectangle {
}

// 地图
Map {
id: map
plugin: osmPlugin
MapView {
id: view
map.plugin: osmPlugin
anchors.fill: parent
center: QtPositioning.coordinate(36, 120)
map.center: QtPositioning.coordinate(36, 120)
smooth: true
zoomLevel: 2
map.zoomLevel: 2
layer.enabled: true
layer.samples: 8

Expand Down Expand Up @@ -75,9 +75,9 @@ Rectangle {

// 画组
const hopPoint = Qt.createQmlObject(`
import QtQuick 2.15
import QtLocation 5.15
import QtPositioning 5.15
import QtQuick
import QtLocation
import QtPositioning
MapItemGroup {
id: hopGroup
Expand Down Expand Up @@ -111,15 +111,15 @@ Rectangle {
border.color: hopGroup.themeColor
}
}
`, map);
`, view.map);

// 设置组属性
hopPoint.latitude = latitude
hopPoint.longitude = longitude
hopPoint.accuracyRadius = accuracyRadius

// 添加到地图
map.addMapItemGroup(hopPoint);
view.map.addMapItemGroup(hopPoint);
}

// 给线添加一个点
Expand All @@ -131,36 +131,36 @@ Rectangle {
// 前往某个区域,并显示提示信息
function gotoCoordinate(latitude, longitude, zoomLevel, message) {
const newPosition = QtPositioning.coordinate(latitude, longitude);
map.center = newPosition;
map.zoomLevel = zoomLevel;
view.map.center = newPosition;
view.map.zoomLevel = zoomLevel;
mapTooltip.sourceItem.text = message;
mapTooltip.coordinate = newPosition;
mapTooltip.visible = true;
}

// 自动调整地图大小
function fitMap() {
map.fitViewportToVisibleMapItems();
view.map.fitViewportToVisibleMapItems();
}

// 清空地图
function clearMap() {
// 清空地图上的物品
map.clearMapItems();
view.map.clearMapItems();

// 清空追踪线
for (const c of tracingLine.path) {
tracingLine.removeCoordinate(c);
}

// 把线加回地图
map.addMapItem(tracingLine);
view.map.addMapItem(tracingLine);

// 隐藏提示信息
mapTooltip.visible = false;

// 把提示信息加回地图
map.addMapItem(mapTooltip);
view.map.addMapItem(mapTooltip);

// 清空已经画过的记录列表
drewPoints.splice(0, drewPoints.length);
Expand Down
2 changes: 1 addition & 1 deletion resolve_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void ResolveCore::run() {
} else {
// 解析失败
auto err = WSAGetLastError();
qCritical() << "[Resolve Core]"
qWarning() << "[Resolve Core]"
<< "Failed to resolve host with error: " << err;
emit setMessage(QString("主机名解析失败,错误代码: %1 。").arg(err));
emit end(false);
Expand Down

0 comments on commit aa3d4fe

Please sign in to comment.