Skip to content

Commit 4c9d4a8

Browse files
committed
Add CMake, Qt5 and Qt6 support
1 parent 05395d8 commit 4c9d4a8

6 files changed

Lines changed: 164 additions & 18 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,5 @@ compile_commands.json
5353

5454
*_qmlcache.qrc
5555

56-
build/**
56+
build/**
57+
build*/**

CMakeLists.txt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
3+
project(qCommTest LANGUAGES CXX)
4+
5+
set(CMAKE_INCLUDE_CURRENT_DIR ON)
6+
set(CMAKE_AUTOUIC ON)
7+
set(CMAKE_AUTOMOC ON)
8+
set(CMAKE_AUTORCC ON)
9+
10+
set(CMAKE_CXX_STANDARD 11)
11+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
12+
13+
# Find Qt
14+
find_package(Qt6 COMPONENTS Core Gui Network SerialPort Widgets REQUIRED)
15+
find_package(Qt5 COMPONENTS Core Gui Network SerialPort Widgets)
16+
17+
if(Qt6_FOUND)
18+
set(QT_VERSION 6)
19+
message(STATUS "Using Qt 6")
20+
set(QT_LIBS Qt6::Core Qt6::Gui Qt6::Network Qt6::SerialPort Qt6::Widgets)
21+
else()
22+
set(QT_VERSION 5)
23+
message(STATUS "Using Qt 5")
24+
set(QT_LIBS Qt5::Core Qt5::Gui Qt5::Network Qt5::SerialPort Qt5::Widgets)
25+
endif()
26+
27+
# Add source files
28+
set(SOURCES
29+
main.cpp
30+
mainwindow.cpp
31+
mainwindow.h
32+
mainwindow.ui
33+
serial_port.cpp
34+
serial_port.h
35+
tcp_server.cpp
36+
tcp_server.h
37+
qdarkstyle/style.qrc
38+
)
39+
40+
# Add executable
41+
add_executable(qCommTest ${SOURCES})
42+
43+
# Link against Qt libraries
44+
target_link_libraries(qCommTest PRIVATE ${QT_LIBS})
45+
46+
# Add icon for Windows
47+
if(WIN32)
48+
set_target_properties(qCommTest PROPERTIES WIN32_EXECUTABLE TRUE)
49+
set(RC_ICONS qdarkstyle/rc/icon.ico)
50+
set(RC_FILE ${CMAKE_CURRENT_BINARY_DIR}/qCommTest.rc)
51+
file(WRITE ${RC_FILE} "IDI_ICON1 ICON DISCARDABLE \"${CMAKE_CURRENT_SOURCE_DIR}/${RC_ICONS}\"")
52+
target_sources(qCommTest PRIVATE ${RC_FILE})
53+
endif()
54+
55+
# Install rules
56+
install(TARGETS qCommTest
57+
RUNTIME DESTINATION bin
58+
LIBRARY DESTINATION lib
59+
ARCHIVE DESTINATION lib
60+
)

README.md

Lines changed: 78 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,86 @@
11
# qCommTest
22

3-
[![License](https://img.shields.io/github/license/diffstorm/ViterbiTrellis)](https://github.com/diffstorm/ViterbiTrellis/blob/main/LICENSE)
4-
[![Language](https://img.shields.io/github/languages/top/diffstorm/ViterbiTrellis)](https://github.com/diffstorm/ViterbiTrellis)
3+
[![License](https://img.shields.io/github/license/diffstorm/qCommTest)](https://github.com/diffstorm/qCommTest/blob/main/LICENSE)
4+
[![Language](https://img.shields.io/github/languages/top/diffstorm/qCommTest)](https://github.com/diffstorm/qCommTest)
55

6-
Serial Communication Test Tool
7-
- Serial COM Port / RS232
8-
- TCP
6+
A simple tool for testing serial (RS232) and TCP communication.
7+
8+
## Features
9+
10+
- **Serial Port Communication:** Test communication with devices connected to serial ports.
11+
- **TCP Server:** Create a TCP server to test network communication.
12+
- **Cross-Platform:** Build and run on Windows, macOS, and Linux.
13+
- **Qt5 and Qt6 Support:** Compatible with both Qt5 and Qt6 versions.
914

1015
## Usage
16+
1117
![Usage](usage.gif)
1218

13-
## :snowman: Author
14-
Eray Öztürk ([@diffstorm](https://github.com/diffstorm))
19+
1. **Configure and start the communication port:**
20+
- For serial communication, select the port, baud rate, and other settings.
21+
- For TCP communication, set the port and start the server.
22+
2. **Run the test code on the device:** The device should send and receive data according to the test protocol.
23+
3. **Observe the log section:** The log section will show the test results and any errors that occur.
24+
25+
## Installation
26+
27+
### Prerequisites
28+
29+
- **CMake:** A cross-platform build system generator.
30+
- **Qt:** A cross-platform application framework. You can use either Qt5 or Qt6.
31+
- **C++ Compiler:** A C++ compiler that is compatible with the Qt version you are using.
32+
33+
### Windows
34+
35+
1. **Install Chocolatey:** If you don't have Chocolatey, install it by following the instructions on the [Chocolatey website](https://chocolatey.org/install).
36+
2. **Install CMake, Qt, and a compiler:**
37+
```bash
38+
choco install cmake qt-creator-ide qt6-base qt6-serialport
39+
```
40+
3. **Build the project:**
41+
```bash
42+
mkdir build
43+
cd build
44+
cmake ..
45+
cmake --build .
46+
```
47+
48+
### macOS
49+
50+
1. **Install Homebrew:** If you don't have Homebrew, install it by following the instructions on the [Homebrew website](https://brew.sh/).
51+
2. **Install CMake and Qt:**
52+
```bash
53+
brew install cmake qt5
54+
```
55+
*Note: You can also use `qt6` instead of `qt5`.*
56+
3. **Build the project:**
57+
```bash
58+
mkdir build
59+
cd build
60+
cmake ..
61+
cmake --build .
62+
```
63+
64+
### Linux (Ubuntu)
65+
66+
1. **Install dependencies:**
67+
```bash
68+
sudo apt-get update
69+
sudo apt-get install build-essential cmake qtcreator qtbase5-dev qtserialport5-dev
70+
```
71+
*Note: For Qt6, you can use `qt6-base-dev` and `qt6-serialport-dev`.*
72+
2. **Build the project:**
73+
```bash
74+
mkdir build
75+
cd build
76+
cmake ..
77+
cmake --build .
78+
```
79+
80+
## Author
81+
82+
Eray Öztürk ([@diffstorm](https://github.com/diffstorm))
83+
84+
## License
1585
16-
## LICENSE
17-
This project is licensed under the [GPL-3 License](LICENSE) - see the LICENSE file for details.
86+
This project is licensed under the [GPL-3.0-only License](LICENSE).

mainwindow.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ void MainWindow::Form_Init()
4646
setWindowFlags(Qt::Widget | Qt::MSWindowsFixedSizeDialogHint | Qt::FramelessWindowHint);
4747
// Right click menu
4848
usageAction = new QAction(tr("U&sage"), this);
49-
connect(usageAction, &QAction::triggered, this, &MainWindow::Usage, Qt::UniqueConnection);
49+
connect(usageAction, &QAction::triggered, this, &MainWindow::Usage);
5050
addAction(usageAction);
5151
aboutAction = new QAction(tr("A&bout"), this);
52-
connect(aboutAction, &QAction::triggered, this, &MainWindow::About, Qt::UniqueConnection);
52+
connect(aboutAction, &QAction::triggered, this, &MainWindow::About);
5353
addAction(aboutAction);
5454
quitAction = new QAction(tr("E&xit"), this);
5555
quitAction->setShortcut(tr("Ctrl+Q"));
56-
connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
56+
connect(quitAction, &QAction::triggered, qApp, &QApplication::quit);
5757
addAction(quitAction);
5858
setContextMenuPolicy(Qt::ActionsContextMenu);
5959
ui->setupUi(this);
@@ -94,7 +94,11 @@ void MainWindow::mousePressEvent(QMouseEvent *event)
9494
{
9595
if(event->button() == Qt::LeftButton)
9696
{
97+
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
9798
m_dragPosition = event->globalPosition().toPoint() - frameGeometry().topLeft();
99+
#else
100+
m_dragPosition = event->globalPos() - frameGeometry().topLeft();
101+
#endif
98102
event->accept();
99103
}
100104
}
@@ -103,7 +107,11 @@ void MainWindow::mouseMoveEvent(QMouseEvent *event)
103107
{
104108
if(event->buttons() & Qt::LeftButton)
105109
{
110+
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
106111
move(event->globalPosition().toPoint() - m_dragPosition);
112+
#else
113+
move(event->globalPos() - m_dragPosition);
114+
#endif
107115
event->accept();
108116
}
109117
}

qCommTest.pro

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# qCommTest - Serial Communication Test Tool
22
QT += core gui network serialport widgets
33

4+
# Add support for Qt6
5+
QT_MAJOR_VERSION = $str_member($split(QT_VERSION, .), 0)
6+
7+
if(equals(QT_MAJOR_VERSION, 6)) {
8+
QT += serialport
9+
}
10+
11+
412
TARGET = qCommTest
513
TEMPLATE = app
614

tcp_server.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,11 @@ void TcpServer::onTimeoutRX()
327327
}
328328
}
329329

330-
void TcpServer::onSocketErrorOccured(QAbstractSocket::SocketError err)
330+
void TcpServer::onSocketErrorOccured(QAbstractSocket::SocketError socketError)
331331
{
332-
switch(err)
332+
switch(socketError)
333333
{
334-
case QTcpSocket::RemoteHostClosedError:
334+
case QAbstractSocket::RemoteHostClosedError:
335335
{
336336
qint64 diff = QDateTime::currentMSecsSinceEpoch() - m_dataSentAt;
337337

@@ -342,12 +342,12 @@ void TcpServer::onSocketErrorOccured(QAbstractSocket::SocketError err)
342342
}
343343
break;
344344

345-
case QTcpSocket::ConnectionRefusedError:
345+
case QAbstractSocket::ConnectionRefusedError:
346346
qDebug() << "TCP Connection refused";
347347
break;
348348

349349
default:
350-
qCritical() << "TCP socket error:" << err << "-" << m_socket->errorString();
350+
qCritical() << "TCP socket error:" << socketError << "-" << m_socket->errorString();
351351
break;
352352
}
353353
}

0 commit comments

Comments
 (0)