ReactivePlusPlus
ReactiveX implementation for C++20
Loading...
Searching...
No Matches
qt_readme.cpp
#include <rpp/rpp.hpp>
#include <rppqt/rppqt.hpp>
#include <QApplication>
#include <QLabel>
#include <QMainWindow>
#include <QPushButton>
#include <QVBoxLayout>
#include <iostream>
int main(int argc, char** argv) // NOLINT(bugprone-exception-escape)
{
QApplication app{argc, argv};
// ![readme]
auto button = new QPushButton("Click me!");
auto label = new QLabel();
rppqt::source::from_signal(*button, &QPushButton::clicked) // <------ react on signals
| rpp::ops::tap([](int) { std::this_thread::sleep_for(std::chrono::milliseconds{500}); }) // some heavy job
| rpp::operators::scan(0, [](int seed, auto) { return ++seed; })
| rpp::operators::observe_on(rppqt::schedulers::main_thread_scheduler{}) // <--- go back to main QT scheduler
| rpp::operators::subscribe([&label](int clicks) {
label->setText(QString{"Clicked %1 times in total!"}.arg(clicks));
});
// ![readme]
QMainWindow window{};
auto vbox = new QVBoxLayout();
vbox->addWidget(button);
vbox->addWidget(label);
window.setCentralWidget(new QWidget);
window.centralWidget()->setLayout(vbox);
window.show();
return app.exec();
}
Scheduler which schedules invoking of schedulables to another thread via queueing tasks with priority...
Definition new_thread.hpp:31
Schedule provided schedulables to main GUI QT thread (where QApplication placed)
Definition main_thread.hpp:32
auto from_signal(const TObject &object, R(TSignalQObject::*signal)(Args...))
Creates rpp::observable that emits a items from provided QT signal.
Definition from_signal.hpp:76
auto scan(InitialValue &&initial_value, Fn &&accumulator)
Apply accumulator function for each emission from observable and result of accumulator from previous ...
Definition scan.hpp:151
auto subscribe(observer< Type, ObserverStrategy > &&observer)
Subscribes passed observer to emissions from this observable.
Definition subscribe.hpp:226
auto observe_on(Scheduler &&scheduler, rpp::schedulers::duration delay_duration={})
Specify the Scheduler on which an observer will observe this Observable.
Definition observe_on.hpp:38