-
Notifications
You must be signed in to change notification settings - Fork 65
Open
Description
We can connect to a Qt signal by using
// [signal] Object::finished(const QString&)
auto output = QtPromise::connect(obj, &Object::finished)
.then([](const QString& data) {
// use the data here to do further work
});
How to implement a promise only resolved when not only the signal emitted but also meet a specific condition?
// task with int task_id
QPromise<int> task = {...}
// [signal] Object::finished(const int&)
task.then([](const int& task_id){
QObject* context = new QObject(this);
return QtPromise::QPromise<Qstring>{[=](const auto& resolve, const auto& reject) {
QObject::connect(this, &Object::finished, context, [=](const int& finshed_id) {
if (task_id == finished_id)
{
resolve("task{} is finished, we can proceed to next", task_id);
delete context;
}
});
})
Would this work? Any elegant solution to handle the context deletion (for disconnect the lambda expression)?
Metadata
Metadata
Assignees
Labels
No labels