summaryrefslogtreecommitdiff
path: root/examples/example-qt.cpp
diff options
context:
space:
mode:
authorPietro Cerutti <gahr@gahr.ch>2014-06-17 15:42:07 +0200
committerJan-Erik Rediger <janerik@fnordig.de>2015-07-27 23:17:41 +0200
commit8ef7d595acd9f4263aa9720dfc57712bbf2cdb33 (patch)
tree604d63c3027e7b8ee300041b0134e0a461636adf /examples/example-qt.cpp
parent3b153cbf9dda2c61af26ad8df2a31b8a5d6a38c8 (diff)
Add Qt adapter and relative example.
Diffstat (limited to 'examples/example-qt.cpp')
-rw-r--r--examples/example-qt.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/examples/example-qt.cpp b/examples/example-qt.cpp
new file mode 100644
index 0000000..f524c3f
--- /dev/null
+++ b/examples/example-qt.cpp
@@ -0,0 +1,46 @@
+#include <iostream>
+using namespace std;
+
+#include <QCoreApplication>
+#include <QTimer>
+
+#include "example-qt.h"
+
+void getCallback(redisAsyncContext *, void * r, void * privdata) {
+
+ redisReply * reply = static_cast<redisReply *>(r);
+ ExampleQt * ex = static_cast<ExampleQt *>(privdata);
+ if (reply == nullptr || ex == nullptr) return;
+
+ cout << "key: " << reply->str << endl;
+
+ ex->finish();
+}
+
+void ExampleQt::run() {
+
+ m_ctx = redisAsyncConnect("localhost", 6379);
+
+ if (m_ctx->err) {
+ cerr << "Error: " << m_ctx->errstr << endl;
+ redisAsyncFree(m_ctx);
+ emit finished();
+ }
+
+ m_adapter.setContext(m_ctx);
+
+ redisAsyncCommand(m_ctx, NULL, NULL, "SET key %s", m_value);
+ redisAsyncCommand(m_ctx, getCallback, this, "GET key");
+}
+
+int main (int argc, char **argv) {
+
+ QCoreApplication app(argc, argv);
+
+ ExampleQt example(argv[argc-1]);
+
+ QObject::connect(&example, SIGNAL(finished()), &app, SLOT(quit()));
+ QTimer::singleShot(0, &example, SLOT(run()));
+
+ return app.exec();
+}