Skip to content

Commit

Permalink
Add support for Qt 6
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrunel committed Jun 26, 2022
1 parent 461f09b commit 9f01c13
Show file tree
Hide file tree
Showing 42 changed files with 889 additions and 894 deletions.
9 changes: 3 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ project(qtpromise VERSION 0.6.0 LANGUAGES CXX)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")

find_package(Qt5 5.6.0 REQUIRED COMPONENTS Core)
find_package(QT 5.6.0 NAMES Qt6 Qt5 REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)

set(CMAKE_AUTOMOC ON)
set(CMAKE_CXX_STANDARD 11)
Expand All @@ -17,7 +18,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_library(qtpromise INTERFACE)
add_library(qtpromise::qtpromise ALIAS qtpromise)

target_link_libraries(qtpromise INTERFACE Qt5::Core)
target_link_libraries(qtpromise INTERFACE Qt${QT_VERSION_MAJOR}::Core)
target_include_directories(qtpromise INTERFACE "${CMAKE_CURRENT_LIST_DIR}/include")

add_definitions(
Expand All @@ -33,7 +34,6 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
-Wpedantic
-Wall
-Wextra

-Wconversion
-Wdouble-promotion
-Wformat=2
Expand All @@ -44,8 +44,6 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
-Wsign-conversion
-Wswitch-default
-Wunused-local-typedefs
# -Wuseless-cast # disabled due to Qt's moc warnings

-pedantic-errors
)

Expand All @@ -68,7 +66,6 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
-Wall
-Wextra
-Wpedantic

-Wsuggest-destructor-override
-Wsuggest-override
)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

[Promises/A+](https://promisesaplus.com/) implementation for [Qt/C++](https://www.qt.io/).

Requires [Qt 5.6](https://www.qt.io/download/) (or later) with [C++11 support enabled](https://wiki.qt.io/How_to_use_C++11_in_your_Qt_Projects).
Requires [Qt 5.6](https://doc.qt.io/qt-5/) (or later) with [C++11 support enabled](https://wiki.qt.io/How_to_use_C++11_in_your_Qt_Projects) or [Qt 6](https://doc.qt.io/qt-6/).

## Documentation

Expand Down
4 changes: 2 additions & 2 deletions cmake/QtPromiseAddTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ function(qtpromise_add_test NAME)
endif()

target_link_libraries(${_TARGET}
Qt5::Concurrent
Qt5::Test
Qt${QT_VERSION_MAJOR}::Concurrent
Qt${QT_VERSION_MAJOR}::Test
qtpromise
qtpromise.tests.utils
${_ARG_LIBRARIES}
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ footer: MIT Licensed | Copyright © Simon Brunel, https://github.com/simonbrunel

[Promises/A+](https://promisesaplus.com/) implementation for [Qt/C++](https://www.qt.io/).

Requires [Qt 5.6](https://www.qt.io/download/) (or later) with [C++11 support enabled](https://wiki.qt.io/How_to_use_C++11_in_your_Qt_Projects).
Requires [Qt 5.6](https://doc.qt.io/qt-5/) (or later) with [C++11 support enabled](https://wiki.qt.io/How_to_use_C++11_in_your_Qt_Projects) or [Qt 6](https://doc.qt.io/qt-6/).

## Documentation

Expand Down
9 changes: 8 additions & 1 deletion src/qtpromise/qpromise_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -578,11 +578,18 @@ struct PromiseConverterBase<T, U, false>
return [](const T& value) {
auto tmp = QVariant::fromValue(value);

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
// https://doc.qt.io/qt-6/qvariant.html#using-canconvert-and-convert-consecutively
if (tmp.canConvert(QMetaType{qMetaTypeId<U>()})
&& tmp.convert(QMetaType{qMetaTypeId<U>()})) {
return qvariant_cast<U>(tmp);
}
#else
// https://doc.qt.io/qt-5/qvariant.html#using-canconvert-and-convert-consecutively
if (tmp.canConvert(qMetaTypeId<U>()) && tmp.convert(qMetaTypeId<U>())) {
return qvariant_cast<U>(tmp);
}

#endif
throw QtPromise::QPromiseConversionException{};
};
}
Expand Down
3 changes: 2 additions & 1 deletion src/qtpromise/qpromiseconnections.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define QTPROMISE_QPROMISECONNECTIONS_H

#include <QtCore/QObject>

#include <memory>

namespace QtPromise {
Expand All @@ -18,7 +19,7 @@ class QPromiseConnections
public:
QPromiseConnections() : m_d(std::make_shared<Data>()) { }

int count() const { return m_d->connections.count(); }
int count() const { return static_cast<int>(m_d->connections.count()); }

void disconnect() const { m_d->disconnect(); }

Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
find_package(Qt5 5.6.0 REQUIRED
find_package(Qt${QT_VERSION_MAJOR} REQUIRED
COMPONENTS
Concurrent
Test
Expand Down
63 changes: 32 additions & 31 deletions tests/auto/qtpromise/benchmark/tst_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
# define EXCEPT_CALL_COPY_CTOR 0
#endif

using namespace QtPromise;

class tst_benchmark : public QObject
{
Q_OBJECT
Expand All @@ -43,7 +41,7 @@ void tst_benchmark::valueResolve()
{
{ // should move the value when resolved by rvalue
Data::logs().reset();
QPromise<Data>{[&](const QPromiseResolve<Data>& resolve) {
QtPromise::QPromise<Data>{[&](const QtPromise::QPromiseResolve<Data>& resolve) {
resolve(Data{42});
}}.wait();

Expand All @@ -54,7 +52,7 @@ void tst_benchmark::valueResolve()
}
{ // should create one copy of the value when resolved by lvalue
Data::logs().reset();
QPromise<Data>{[&](const QPromiseResolve<Data>& resolve) {
QtPromise::QPromise<Data>{[&](const QtPromise::QPromiseResolve<Data>& resolve) {
Data value{42};
resolve(value);
}}.wait();
Expand All @@ -70,7 +68,8 @@ void tst_benchmark::valueReject()
{
{ // should not create any data if rejected
Data::logs().reset();
QPromise<Data>{[&](const QPromiseResolve<Data>&, const QPromiseReject<Data>& reject) {
QtPromise::QPromise<Data>{[&](const QtPromise::QPromiseResolve<Data>&,
const QtPromise::QPromiseReject<Data>& reject) {
reject(QString{"foo"});
}}.wait();

Expand All @@ -83,10 +82,10 @@ void tst_benchmark::valueReject()

void tst_benchmark::valueThen()
{
{ // should not copy value on continutation if fulfilled
{ // should not copy value on continuation if fulfilled
int value = -1;
Data::logs().reset();
QPromise<Data>::resolve(Data{42})
QtPromise::QPromise<Data>::resolve(Data{42})
.then([&](const Data& res) {
value = res.value();
})
Expand All @@ -98,11 +97,11 @@ void tst_benchmark::valueThen()
QCOMPARE(Data::logs().refs, 0);
QCOMPARE(value, 42);
}
{ // should not create value on continutation if rejected
{ // should not create value on continuation if rejected
int value = -1;
QString error;
Data::logs().reset();
QPromise<Data>::reject(QString{"foo"})
QtPromise::QPromise<Data>::reject(QString{"foo"})
.then(
[&](const Data& res) {
value = res.value();
Expand All @@ -122,7 +121,7 @@ void tst_benchmark::valueThen()
{ // should move the returned value when fulfilled
int value = -1;
Data::logs().reset();
QPromise<int>::resolve(42)
QtPromise::QPromise<int>::resolve(42)
.then([&](int res) {
return Data{res + 2};
})
Expand All @@ -139,7 +138,7 @@ void tst_benchmark::valueThen()
}
{ // should not create any data if handler throws
Data::logs().reset();
QPromise<int>::resolve(42)
QtPromise::QPromise<int>::resolve(42)
.then([&](int res) {
throw QString{"foo"};
return Data{res + 2};
Expand All @@ -155,12 +154,12 @@ void tst_benchmark::valueThen()

void tst_benchmark::valueDelayed()
{
{ // should not copy the value on continutation if fulfilled
{ // should not copy the value on continuation if fulfilled
int value = -1;
Data::logs().reset();
QPromise<int>::resolve(42)
QtPromise::QPromise<int>::resolve(42)
.then([&](int res) {
return QPromise<Data>::resolve(Data{res + 1});
return QtPromise::QPromise<Data>::resolve(Data{res + 1});
})
.then([&](const Data& res) {
value = res.value();
Expand All @@ -173,11 +172,11 @@ void tst_benchmark::valueDelayed()
QCOMPARE(Data::logs().refs, 0);
QCOMPARE(value, 43);
}
{ // should not create value on continutation if rejected
{ // should not create value on continuation if rejected
Data::logs().reset();
QPromise<int>::resolve(42)
QtPromise::QPromise<int>::resolve(42)
.then([&]() {
return QPromise<Data>::reject(QString{"foo"});
return QtPromise::QPromise<Data>::reject(QString{"foo"});
})
.wait();

Expand All @@ -190,10 +189,10 @@ void tst_benchmark::valueDelayed()

void tst_benchmark::valueFinally()
{
{ // should not copy the value on continutation if fulfilled
{ // should not copy the value on continuation if fulfilled
int value = -1;
Data::logs().reset();
QPromise<Data>::resolve(Data{42})
QtPromise::QPromise<Data>::resolve(Data{42})
.finally([&]() {
value = 42;
})
Expand All @@ -205,10 +204,10 @@ void tst_benchmark::valueFinally()
QCOMPARE(Data::logs().refs, 0);
QCOMPARE(value, 42);
}
{ // should not create value on continutation if rejected
{ // should not create value on continuation if rejected
int value = -1;
Data::logs().reset();
QPromise<Data>::reject(QString{"foo"})
QtPromise::QPromise<Data>::reject(QString{"foo"})
.finally([&]() {
value = 42;
})
Expand All @@ -224,10 +223,10 @@ void tst_benchmark::valueFinally()

void tst_benchmark::valueTap()
{
{ // should not copy the value on continutation if fulfilled
{ // should not copy the value on continuation if fulfilled
int value = -1;
Data::logs().reset();
QPromise<Data>::resolve(Data{42})
QtPromise::QPromise<Data>::resolve(Data{42})
.tap([&](const Data& res) {
value = res.value();
})
Expand All @@ -239,10 +238,10 @@ void tst_benchmark::valueTap()
QCOMPARE(Data::logs().refs, 0);
QCOMPARE(value, 42);
}
{ // should not create value on continutation if rejected
{ // should not create value on continuation if rejected
int value = -1;
Data::logs().reset();
QPromise<Data>::reject(QString{"foo"})
QtPromise::QPromise<Data>::reject(QString{"foo"})
.tap([&](const Data& res) {
value = res.value();
})
Expand All @@ -260,7 +259,8 @@ void tst_benchmark::errorReject()
{
{ // should create one copy of the error when rejected by rvalue
Data::logs().reset();
QPromise<int>{[&](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
QtPromise::QPromise<int>{[&](const QtPromise::QPromiseResolve<int>&,
const QtPromise::QPromiseReject<int>& reject) {
reject(Data{42});
}}.wait();

Expand All @@ -271,7 +271,8 @@ void tst_benchmark::errorReject()
}
{ // should create one copy of the error when rejected by lvalue (no extra copy)
Data::logs().reset();
QPromise<int>{[&](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
QtPromise::QPromise<int>{[&](const QtPromise::QPromiseResolve<int>&,
const QtPromise::QPromiseReject<int>& reject) {
Data error{42};
reject(error);
}}.wait();
Expand All @@ -285,10 +286,10 @@ void tst_benchmark::errorReject()

void tst_benchmark::errorThen()
{
{ // should not copy error on continutation if rejected
{ // should not copy error on continuation if rejected
int value = -1;
Data::logs().reset();
QPromise<void>::reject(Data{42})
QtPromise::QPromise<void>::reject(Data{42})
.fail([&](const Data& res) {
value = res.value();
})
Expand All @@ -301,10 +302,10 @@ void tst_benchmark::errorThen()
QCOMPARE(Data::logs().refs, 0);
QCOMPARE(value, 42);
}
{ // should not copy error on continutation if rethrown
{ // should not copy error on continuation if rethrown
int value = -1;
Data::logs().reset();
QPromise<void>::reject(Data{42})
QtPromise::QPromise<void>::reject(Data{42})
.fail([](const Data&) {
throw;
})
Expand Down
18 changes: 8 additions & 10 deletions tests/auto/qtpromise/cpp14/tst_resolver_lambda_auto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

#include <memory>

using namespace QtPromise;

class tst_cpp14_resolver_lambda_auto : public QObject
{
Q_OBJECT
Expand All @@ -28,19 +26,19 @@ QTEST_MAIN(tst_cpp14_resolver_lambda_auto)

void tst_cpp14_resolver_lambda_auto::resolverTwoAutoArgs()
{
QPromise<int> p0{[](auto resolve, auto reject) {
QtPromise::QPromise<int> p0{[](auto resolve, auto reject) {
Q_UNUSED(reject)
resolve(42);
}};
QPromise<int> p1{[](auto resolve, const auto& reject) {
QtPromise::QPromise<int> p1{[](auto resolve, const auto& reject) {
Q_UNUSED(reject)
resolve(42);
}};
QPromise<int> p2{[](const auto& resolve, auto reject) {
QtPromise::QPromise<int> p2{[](const auto& resolve, auto reject) {
Q_UNUSED(reject)
resolve(42);
}};
QPromise<int> p3{[](const auto& resolve, const auto& reject) {
QtPromise::QPromise<int> p3{[](const auto& resolve, const auto& reject) {
Q_UNUSED(reject)
resolve(42);
}};
Expand All @@ -54,19 +52,19 @@ void tst_cpp14_resolver_lambda_auto::resolverTwoAutoArgs()

void tst_cpp14_resolver_lambda_auto::resolverTwoAutoArgs_void()
{
QPromise<void> p0{[](auto resolve, auto reject) {
QtPromise::QPromise<void> p0{[](auto resolve, auto reject) {
Q_UNUSED(reject)
resolve();
}};
QPromise<void> p1{[](auto resolve, const auto& reject) {
QtPromise::QPromise<void> p1{[](auto resolve, const auto& reject) {
Q_UNUSED(reject)
resolve();
}};
QPromise<void> p2{[](const auto& resolve, auto reject) {
QtPromise::QPromise<void> p2{[](const auto& resolve, auto reject) {
Q_UNUSED(reject)
resolve();
}};
QPromise<void> p3{[](const auto& resolve, const auto& reject) {
QtPromise::QPromise<void> p3{[](const auto& resolve, const auto& reject) {
Q_UNUSED(reject)
resolve();
}};
Expand Down
Loading

0 comments on commit 9f01c13

Please sign in to comment.