Small fixes
This commit is contained in:
parent
0196d4ab36
commit
ec4da11bb8
24
.gitattributes
vendored
Normal file
24
.gitattributes
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# Set default behavior to automatically normalize line endings
|
||||||
|
* text=auto
|
||||||
|
|
||||||
|
# C++ source files
|
||||||
|
*.cpp text diff=cpp
|
||||||
|
*.h text diff=cpp
|
||||||
|
|
||||||
|
# CMake files
|
||||||
|
CMakeLists.txt text
|
||||||
|
*.cmake text
|
||||||
|
|
||||||
|
# QMake files
|
||||||
|
*.pro text
|
||||||
|
|
||||||
|
# Bash scripts
|
||||||
|
*.sh text eol=lf
|
||||||
|
|
||||||
|
# Documentation
|
||||||
|
*.md text diff=markdown
|
||||||
|
|
||||||
|
# Binary files
|
||||||
|
*.png binary
|
||||||
|
*.jpg binary
|
||||||
|
*.ico binary
|
||||||
31
.github/workflows/build.yml
vendored
Normal file
31
.github/workflows/build.yml
vendored
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
name: Build Qt Calculator
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ main ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Install Qt
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y qtbase5-dev qt5-qmake cmake
|
||||||
|
|
||||||
|
- name: Configure CMake
|
||||||
|
run: cmake -B ${{github.workspace}}/build
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: cmake --build ${{github.workspace}}/build
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
working-directory: ${{github.workspace}}/build
|
||||||
|
run: |
|
||||||
|
echo "Running built application to verify it works"
|
||||||
|
# Add tests if you implement them later
|
||||||
@ -8,9 +8,26 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -g")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -g")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
find_package(Qt5 REQUIRED COMPONENTS Core Widgets)
|
# Установить пути поиска для Qt5
|
||||||
|
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "/usr/lib/qt5" "/usr/lib/x86_64-linux-gnu/qt5" "/usr/lib/cmake/Qt5")
|
||||||
|
|
||||||
|
# Альтернативный способ поиска Qt5
|
||||||
|
if(NOT Qt5_DIR)
|
||||||
|
set(Qt5_DIR "/usr/lib/cmake/Qt5")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Настройка Qt5 и пути модулей
|
||||||
|
find_package(Qt5 COMPONENTS Core Widgets QUIET)
|
||||||
|
|
||||||
|
# Проверка наличия Qt5
|
||||||
|
if(NOT Qt5_FOUND)
|
||||||
|
message(FATAL_ERROR "Qt5 не найден. Установите пакеты Qt5: sudo apt install qtbase5-dev qt5-qmake")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Включение автоматической генерации MOC-файлов для Qt
|
||||||
set(CMAKE_AUTOMOC ON)
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
set(CMAKE_AUTORCC ON)
|
||||||
|
set(CMAKE_AUTOUIC ON)
|
||||||
|
|
||||||
add_executable(Calculator main.cpp
|
add_executable(Calculator main.cpp
|
||||||
Calculator.cpp
|
Calculator.cpp
|
||||||
|
|||||||
@ -83,8 +83,8 @@
|
|||||||
|
|
||||||
void Calculator::digitClicked()
|
void Calculator::digitClicked()
|
||||||
{
|
{
|
||||||
const auto *button = qobject_cast<QPushButton *>(sender()); // const auto*
|
const auto *button = qobject_cast<QPushButton *>(sender());
|
||||||
const QString digit = button -> text(); // const
|
const QString digit = button->text();
|
||||||
|
|
||||||
if (waitingForOperand) {
|
if (waitingForOperand) {
|
||||||
display->clear();
|
display->clear();
|
||||||
|
|||||||
78
README.md
78
README.md
@ -3,18 +3,86 @@ # Qt Calculator
|
|||||||
A simple calculator application built with Qt5 and C++20.
|
A simple calculator application built with Qt5 and C++20.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- Basic arithmetic operations (+, -, *, /)
|
- Basic arithmetic operations (+, -, *, /)
|
||||||
- Clear functionality
|
- Clear functionality
|
||||||
- Error handling for division by zero
|
- Error handling for division by zero
|
||||||
- Modern C++ practices (Rule of Five)
|
- Modern C++ practices (Rule of Five implementation)
|
||||||
|
|
||||||
## Build Requirements
|
## Requirements
|
||||||
- Qt5 (Core, Widgets)
|
|
||||||
- CMake 3.16+
|
To compile and run this project, you need:
|
||||||
|
|
||||||
|
- CMake 3.16 or higher
|
||||||
|
- Qt5 (Core and Widgets)
|
||||||
- C++20 compatible compiler
|
- C++20 compatible compiler
|
||||||
|
|
||||||
## Building
|
## Installing Dependencies
|
||||||
|
|
||||||
|
### Ubuntu/Debian:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Full development environment
|
||||||
|
sudo apt install qtcreator qtbase5-dev qt5-qmake qtbase5-dev-tools cmake
|
||||||
|
|
||||||
|
# Minimal required packages
|
||||||
|
sudo apt install qtbase5-dev qt5-qmake cmake
|
||||||
|
```
|
||||||
|
|
||||||
|
### Verifying Qt5 Installation
|
||||||
|
|
||||||
|
Check if Qt5 packages are installed and locate them:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
dpkg -l | grep qt5
|
||||||
|
find /usr -name "Qt5Config.cmake"
|
||||||
|
```
|
||||||
|
|
||||||
|
If Qt5Config.cmake is not found, install the necessary packages:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo apt install qtbase5-dev
|
||||||
|
```
|
||||||
|
|
||||||
|
### Fedora:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo dnf install qt5-qtbase-devel qt5-qttools-devel qt-creator cmake
|
||||||
|
```
|
||||||
|
|
||||||
|
### Arch Linux:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo pacman -S qt5-base qt5-tools qtcreator cmake
|
||||||
|
```
|
||||||
|
|
||||||
|
## Building the Project
|
||||||
|
|
||||||
|
### Using CMake (recommended)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
mkdir build && cd build
|
mkdir build && cd build
|
||||||
cmake ..
|
cmake ..
|
||||||
make
|
make
|
||||||
|
```
|
||||||
|
|
||||||
|
### Using QMake (alternative)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
qmake qt-project.pro
|
||||||
|
make
|
||||||
|
```
|
||||||
|
|
||||||
|
## Running the Application
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./Calculator
|
||||||
|
```
|
||||||
|
|
||||||
|
## Troubleshooting Qt5 Find Issues
|
||||||
|
|
||||||
|
If CMake cannot find Qt5, you can specify the Qt5 path manually:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cmake -DQt5_DIR=/path/to/qt5/lib/cmake/Qt5 ..
|
||||||
|
```
|
||||||
21
build.sh
Normal file
21
build.sh
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Check for Qt5 installation
|
||||||
|
if ! dpkg -l | grep -q qtbase5-dev; then
|
||||||
|
echo "Qt5 is not installed. Installing required packages..."
|
||||||
|
sudo apt install -y qtbase5-dev qt5-qmake cmake
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create build directory
|
||||||
|
mkdir -p build
|
||||||
|
cd build
|
||||||
|
|
||||||
|
# Configure CMake with Qt5 paths
|
||||||
|
cmake .. \
|
||||||
|
-DQt5_DIR=/usr/lib/cmake/Qt5 \
|
||||||
|
-DCMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu/cmake
|
||||||
|
|
||||||
|
# Build the project
|
||||||
|
make
|
||||||
|
|
||||||
|
echo "Build completed. Run the calculator with: ./build/Calculator"
|
||||||
17
qt-project.pro
Normal file
17
qt-project.pro
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# Alternative project file for Qt Creator and qmake
|
||||||
|
|
||||||
|
QT += core widgets
|
||||||
|
CONFIG += c++20
|
||||||
|
|
||||||
|
TARGET = Calculator
|
||||||
|
TEMPLATE = app
|
||||||
|
|
||||||
|
SOURCES += main.cpp \
|
||||||
|
Calculator.cpp
|
||||||
|
|
||||||
|
HEADERS += Calculator.h
|
||||||
|
|
||||||
|
# Default rules for deployment.
|
||||||
|
qnx: target.path = /tmp/$${TARGET}/bin
|
||||||
|
else: unix:!android: target.path = /opt/$${TARGET}/bin
|
||||||
|
!isEmpty(target.path): INSTALLS += target
|
||||||
Loading…
Reference in New Issue
Block a user