我写了一个函数,它返回一对QDateTime
可观察的,就像这个:
rxcpp::observable<std::tuple<QDateTime, QDateTime>> experimentOne(const QDateTimeAxis * const axis
{
return rxcpp::observable<>::create<std::tuple<QDateTime, QDateTime>>(
[axis](rxcpp::subscriber<std::tuple<QDateTime, QDateTime>> s) {
auto rangeCallback = [s](QDateTime minv, QDateTime maxv) {
if (s.is_subscribed()) {
// send to the subscriber
s.on_next(std::make_tuple<QDateTime, QDateTime>(std::move(minv), std::move(maxv)));
}
};
QObject::connect(axis, &QDateTimeAxis::rangeChanged, rangeCallback);
});
}
因此,使用此功能,我可以订阅 a 轴上日期范围的更改QChart
。
我还写了另一个函数,给定两个日期,返回一个带有来自 sqlite db 的值的 observable,如下所示
rxcpp::observable<std::tuple<double, double>> Database::getValueRange(const std::string& table, unsigned long start, unsigned long end)
{
return rxcpp::observable<>::create<std::tuple<double, double>>(
[this, table, start, end](rxcpp::subscriber<std::tuple<double, double>> s) {
// get the prepared statement for the query 1, i.e. ohlcv values
// within a date range
sqlite3_stmt *stmt = this->m_query3_stms[table].get();
// bind first parameter, the start timestamp
int rc = sqlite3_bind_int64(stmt, 1, start);
checkSqliteCode(rc, m_db.get());
// bind the second parameter, the end timestamp
rc = sqlite3_bind_int64(stmt, 2, end);
checkSqliteCode(rc, m_db.get());
// step through the query results
while ( sqlite3_step(stmt)==SQLITE_ROW && s.is_subscribed() ) {
// extract name values from the current result row
float minv = sqlite3_column_double(stmt, 0);
float maxv = sqlite3_column_double(stmt, 1);
// send to the subscriber
s.on_next(std::make_tuple<double, double>(minv, maxv));
}
// reset the statement for reuse
sqlite3_reset(stmt);
// send complete to the subscriber
s.on_completed();
});
}
如何在 RxCpp 中以惯用的形式将第一个函数(两个日期)的值作为输入传递给第二个函数?在管道结束时,我可以根据输入日期订阅来自数据库的值吗?