2
* Copyright © 2014 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3,
6
* as published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17
* Thomas Voß <thomas.voss@canonical.com>
20
#ifndef QT_CORE_WORLD_BRIDGE_H_
21
#define QT_CORE_WORLD_BRIDGE_H_
36
* @brief Sets up the Qt core world and executes its event loop. Blocks until destroy() is called.
37
* @param argc Number of arguments in argv.
38
* @param argv Array of command-line arguments.
39
* @param ready Functor be called when the world has been setup and is about to be executed.
40
* @throw std::runtime_error in case of errors.
42
void build_and_run(int argc, char** argv, const std::function<void()>& ready);
45
* @brief Destroys the Qt core world and quits its event loop.
50
* @brief Enters the Qt core world and schedules the given task for execution.
51
* @param task The task to be executed in the Qt core world.
52
* @return A std::future that can be waited for to synchronize to the world's internal event loop.
54
std::future<void> enter_with_task(const std::function<void()>& task);
58
* @brief Enters the Qt core world and schedules the given task for execution.
59
* @param task The task to be executed in the Qt core world.
60
* @return A std::future that can be waited for to get hold of the result of the task.
63
inline std::future<T> enter_with_task_and_expect_result(const std::function<T()>& task)
65
std::shared_ptr<std::promise<T>> promise = std::make_shared<std::promise<T>>();
66
std::future<T> future = promise->get_future();
68
auto t = [promise, task]()
72
promise->set_value(task());
75
promise->set_exception(std::current_exception());
87
#endif // QT_CORE_WORLD_BRIDGE_H_