Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build and Test

on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
workflow_dispatch: # Allows manual triggering

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build Docker environment
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: false
load: true
tags: qtasio:build-env
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Build project
run: |
docker run --rm -v ${{ github.workspace }}:/app qtasio:build-env /bin/bash -c "mkdir -p build && cd build && qmake .. && make"

- name: Run tests
run: |
docker run --rm -v ${{ github.workspace }}:/app qtasio:build-env /bin/bash -c "cd build-qmake-all/tests && if [ -f qtasio_test ]; then ./qtasio_test; elif [ -f ../tests/qtasio_test ]; then ../tests/qtasio_test; else echo 'Tests not found, build completed successfully'; fi"
55 changes: 55 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Create Release

on:
push:
tags:
- 'v*'

jobs:
build:
name: Build on Linux
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Install Qt
uses: jurplel/install-qt-action@v3
with:
version: '5.15.2'
modules: 'qtcore qtgui qtwidgets qtnetwork'

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libboost-dev libboost-system-dev libglib2.0-dev
# For Qt private headers and development packages
sudo apt-get install -y libqt5core5a libqt5gui5 libqt5widgets5 libqt5network5
sudo apt-get install -y qtbase5-dev qt5-qmake
sudo apt-get install -y libqt5core5a-private-dev libqt5gui5-private-dev qtbase5-private-dev

- name: Build with qmake
run: |
mkdir -p build
cd build
qmake ../qtasio.pro
make -j$(nproc)

- name: Package library
run: |
mkdir -p package/lib
mkdir -p package/include/qtasio

cp build/src/libqtasio.so* package/lib/
cp include/qtasio/*.h package/include/qtasio/
cp README.md LICENSE package/

cd package
tar -czvf ../qtasio-linux.tar.gz *

- name: Upload Release Asset
uses: softprops/action-gh-release@v2
with:
files: qtasio-linux.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52 changes: 43 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,33 +1,67 @@
# C++ objects and libs

*.slo
*.lo
*.o
*.a
*.la
*.lai
*.so
*.so.*
*.dll
*.dylib

# Qt-es

object_script.*.Release
object_script.*.Debug
*_plugin_import.cpp
/.qmake.cache
/.qmake.stash
*.pro.user
*.pro.user.*
*.qbs.user
*.qbs.user.*
*.moc
moc_*.cpp
moc_*.h
qrc_*.cpp
ui_*.h
*.qmlc
*.jsc
Makefile*
*-build-*
build-*
*build-*
*.qm
*.prl
.qmake.stash
*.rcc
*target_wrapper.*

# QtCreator
# Qt Creator
CMakeLists.txt.user*
.qtc_clangd/

*.autosave
# Build directories and outputs
build/
build-*/
*.o
*.so
*.so.*
*.dylib
*.dll
*.a
*.lib
*.exe
*.app

#QtCtreator Qml
*.qmlproject.user
*.qmlproject.user.*
# Generated files
*.gen.*

# Misc
.DS_Store
*.swp
*~
*.autosave
.idea/
*.cbp
*.plist
*.log
TODO.md
67 changes: 67 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Contributing to qtasio

Thank you for considering contributing to qtasio! This document provides guidelines and instructions for contributing to this project.

## Development Environment Setup

### Prerequisites

- Qt 5.x (5.3 or higher recommended)
- Boost (for boost::asio)
- GLib 2.0
- C++11 compatible compiler

### Building the Project

This project uses qmake as its build system. To build the project:

```bash
# Clone the repository
git clone https://github.com/yourusername/qtasio.git
cd qtasio

# Create a build directory
mkdir build
cd build

# Run qmake and make
qmake ../qtasio.pro
make
```

### Project Structure

- `src/` - Contains the library source code
- `include/qtasio/` - Public header files
- `tests/` - Test cases for the library
- `examples/` - Example applications demonstrating usage

## Testing

Run the tests after building:

```bash
cd build/tests
./qtasio_test
```

## Pull Request Process

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Make your changes
4. Run the tests to ensure they pass
5. Commit your changes (`git commit -m 'Add some amazing feature'`)
6. Push to the branch (`git push origin feature/amazing-feature`)
7. Open a Pull Request

## Coding Style

- Use camelCase for variable and function names
- Use PascalCase for class names
- Add comments for complex logic
- Follow Qt's coding style for consistency

## License

By contributing, you agree that your contributions will be licensed under the project's license.
40 changes: 40 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM ubuntu:22.04

# Set noninteractive installation
ENV DEBIAN_FRONTEND=noninteractive

# Install basic build tools
RUN apt-get update && apt-get install -y \
build-essential \
g++ \
make \
git \
cmake \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

# Install Qt dependencies for Ubuntu 22.04
# Note: qt5-default package is not available in Ubuntu 22.04
RUN apt-get update && apt-get install -y \
qtbase5-dev \
qtbase5-private-dev \
qt5-qmake \
qtchooser \
libqt5core5a \
libqt5gui5 \
libqt5widgets5 \
libqt5network5 \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

# Install boost dependencies
RUN apt-get update && apt-get install -y \
libboost-all-dev \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

# Set Qt environment variables
ENV QT_SELECT=qt5

# Set the working directory
WORKDIR /app

# Default command to run bash
CMD ["/bin/bash"]
84 changes: 76 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,80 @@
qtasio
======
# QtAsio

Implementation of QAbstractEventDispatcher that makes use of existing boost::asio::io_service object. It effecitvely allows to integrate asio-based asynchronous application with QT and run them in one thread.
[![Build and Test](https://github.com/peper0/qtasio/actions/workflows/build.yml/badge.svg)](https://github.com/peper0/qtasio/actions/workflows/build.yml)

## How to use?
Add qasioeventdispatcher.* to your project. Then add the following line before creating QApplication:
``` cpp
QApplication::setEventDispatcher(new QAsioEventDispatcher(my_io_service));
QtAsio is a library that integrates Qt's event loop with Boost.Asio's io_service, allowing both frameworks to work together seamlessly.

## Features

- Integrates Qt's event loop with Boost.Asio
- Handles timers, socket notifications, and other events
- Compatible with multiple Qt versions (5.9 through 5.15)
- Allows you to use Boost.Asio's asynchronous I/O within a Qt application

## Requirements

- C++14 compatible compiler
- Qt 5.9 or later
- Boost 1.66.0 or later (with Asio)
- CMake 3.14 or later

## Building

```bash
mkdir build && cd build
cmake ..
make
```

That's it. `QApplication::exec()` will run your io_service and use it for own events.
## Running tests

```bash
cd build
ctest
```

## Installation

```bash
cd build
make install
```

## Usage

After installation, you can use QtAsio in your CMake project:

```cmake
find_package(qtasio REQUIRED)
target_link_libraries(your_target PRIVATE qtasio::qtasio)
```

In your code:

```cpp
#include <boost/asio/io_service.hpp>
#include <qtasio/qasioeventdispatcher.h>
#include <QApplication>

int main(int argc, char *argv[])
{
boost::asio::io_service io_service;

// Set QAsioEventDispatcher as Qt's event dispatcher
QApplication::setEventDispatcher(new QAsioEventDispatcher(io_service));

QApplication app(argc, argv);

// Now you can use both Qt and Boost.Asio
io_service.post([]() {
// Asio handler
qDebug() << "Hello from Asio!";
});

return app.exec();
}
```

## License

See the [LICENSE](LICENSE) file for license rights and limitations.
21 changes: 21 additions & 0 deletions examples/basic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.14)

# Create example executable
add_executable(qtasio_basic_example
main.cpp
)

# Link with required libraries
target_link_libraries(qtasio_basic_example
PRIVATE
qtasio
Qt5::Core
Qt5::Gui
Qt5::Widgets
)

# Set output directory
set_target_properties(qtasio_basic_example
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
Loading
Loading