diff --git a/AiAnalysis.pro b/AiAnalysis.pro new file mode 100644 index 0000000..1c8080c --- /dev/null +++ b/AiAnalysis.pro @@ -0,0 +1,24 @@ +QT += core gui network +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = AiAnalysis +TEMPLATE = app + +CONFIG += c++11 + +# Qt 5.9 兼容,不使用 c++17 +*-g++*: QMAKE_CXXFLAGS += -std=c++11 +*-msvc*: QMAKE_CXXFLAGS += /std:c++11 + +SOURCES += \ + main.cpp \ + mainwindow.cpp \ + udpreceiver.cpp \ + plotwidget.cpp \ + datamanager.cpp + +HEADERS += \ + mainwindow.h \ + udpreceiver.h \ + plotwidget.h \ + datamanager.h diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 25c16a7..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -cmake_minimum_required(VERSION 3.14) -project(AiAnalysis LANGUAGES CXX) - -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_AUTOMOC ON) - -find_package(Qt5 REQUIRED COMPONENTS Core Widgets Network) - -add_executable(AiAnalysis - main.cpp - mainwindow.cpp - mainwindow.h - udpreceiver.cpp - udpreceiver.h - plotwidget.cpp - plotwidget.h - datamanager.cpp - datamanager.h -) - -target_link_libraries(AiAnalysis Qt5::Core Qt5::Widgets Qt5::Network) diff --git a/README.md b/README.md index d583e99..4963c50 100644 --- a/README.md +++ b/README.md @@ -12,52 +12,30 @@ ## 跨平台支持 ✅ Linux ✅ Windows ✅ macOS -代码纯Qt5编写,无平台特定依赖。 +纯Qt5 + qmake构建,无额外依赖。支持 Qt 5.9+。 --- -## Windows 编译 & 运行 +## Windows / Linux / macOS 编译 & 运行 -### 准备工作 -1. 下载安装 **Qt 5.15** (MinGW 或 MSVC 版本均支持): https://download.qt.io/archive/qt/5.15/ - - 安装时勾选 `MinGW` 编译器 或 `MSVC` 编译器 -2. 下载安装 **CMake** (3.14+): https://cmake.org/download/ - - 安装时勾选 "Add CMake to system PATH" - -### 编译(命令行) -```powershell -# 在项目目录下 -mkdir build -cd build -cmake .. -G "MinGW Makefiles" -mingw32-make -j4 -# 或使用 MSVC: -# cmake .. -G "Visual Studio 17 2022" -``` - -### 编译(Qt Creator) +### Qt Creator(推荐) 1. 打开 Qt Creator -2. File → Open File or Project → 选择 `CMakeLists.txt` -3. 选择对应的 Kit(MinGW 64-bit 或 MSVC) -4. 点击构建 → 运行 +2. **File → Open File or Project** → 选择 `AiAnalysis.pro` +3. 选择对应的 Kit(如 Desktop Qt 5.9.8 MinGW 32bit) +4. 点击左下角🔨构建 → ▶️运行 -### 直接运行 -编译完成后,`build/AiAnalysis.exe` 即为可执行文件。 +### 命令行(qmake) +```bash +qmake AiAnalysis.pro +make -j4 # Linux/macOS +mingw32-make -j4 # Windows MinGW +``` --- -## Linux 编译 -```bash -sudo apt install qtbase5-dev cmake g++ -mkdir build && cd build -cmake .. -make -j$(nproc) -./AiAnalysis -``` - ## 使用说明 1. 输入UDP端口号,点击「开始监听」 -2. 下位机通过UDP发送逗号分隔的16通道数据 +2. 下位机通过UDP发送逗号分隔的16通道数据,如:`17309,13624,17301,...` 3. 右侧面板可切换通道显示/隐藏 4. 「打开文件」可加载历史CSV数据回放 -5. 鼠标滚轮缩放Y轴,右键拖拽平移,双击恢复自动范围 +5. 滚轮缩放Y轴 | 右键拖拽平移 | 双击恢复自动范围 diff --git a/mainwindow.cpp b/mainwindow.cpp index 62a0f14..8643a31 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -90,7 +90,7 @@ void MainWindow::setupUi() "QSpinBox { background: #2a2a3e; color: #fff; border: 1px solid #555; " "border-radius: 4px; padding: 4px; font-size: 13px; }" ); - connect(m_displaySpinBox, QOverload::of(&QSpinBox::valueChanged), + connect(m_displaySpinBox, static_cast(&QSpinBox::valueChanged), this, &MainWindow::onDisplayPointsChanged); controlLayout->addWidget(portLabel); @@ -284,7 +284,7 @@ void MainWindow::onDataReceived(const QByteArray &data) if (raw.isEmpty()) return; // 可能一个UDP包包含多行 - QStringList lines = raw.split('\n', Qt::SkipEmptyParts); + QStringList lines = raw.split('\n', QString::SkipEmptyParts); for (const QString &line : lines) { processDataLine(line.trimmed()); } diff --git a/plotwidget.cpp b/plotwidget.cpp index a97626d..906911f 100644 --- a/plotwidget.cpp +++ b/plotwidget.cpp @@ -394,7 +394,7 @@ void PlotWidget::drawLegend(QPainter &painter) void PlotWidget::wheelEvent(QWheelEvent *event) { QRectF area = plotArea(); - if (!area.contains(event->position())) return; + if (!area.contains(event->posF())) return; double zoomFactor = 1.15; if (event->angleDelta().y() < 0) {