diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2017-03-20 22:07:15 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2017-03-20 22:07:15 +0900 |
commit | 567d75fd47b185e6906f34b7c4aef0952b5c2f50 (patch) | |
tree | ed0ffbe7e32fba7f3a04af879ec23147565e7f88 /examples | |
parent | f0f4645efcad290423fa500f495743ff594dfbb0 (diff) | |
download | libquotient-567d75fd47b185e6906f34b7c4aef0952b5c2f50.tar.gz libquotient-567d75fd47b185e6906f34b7c4aef0952b5c2f50.zip |
Added an example of libqmatrixclient usage
Compile and run with your username and password as the first two arguments.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/qmc-example.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/examples/qmc-example.cpp b/examples/qmc-example.cpp new file mode 100644 index 00000000..36446255 --- /dev/null +++ b/examples/qmc-example.cpp @@ -0,0 +1,43 @@ +#include <iostream> +#include <QCoreApplication> + +#include "connection.h" +#include "room.h" + +int main(int argc, char* argv[]) +{ + using namespace QMatrixClient; + using std::cout; + using std::endl; + + QCoreApplication app(argc, argv); + if (argc < 2) + return -1; + + auto conn = new Connection(QUrl("https://matrix.org")); + conn->connectToServer(argv[1], argv[2]); + QObject::connect(conn, &Connection::connected, [=] { + cout << "Connected" << endl; + conn->sync(); + }); + QObject::connect(conn, &Connection::syncDone, [=] { + cout << "Sync done" << endl; + conn->sync(30000); + }); + QObject::connect(conn, &Connection::newRoom, [=] (Room* r) { + cout << "New room: " << r->id().toStdString() << endl; + QObject::connect(r, &Room::namesChanged, [=] { + cout << "Room " << r->id().toStdString() << ", name(s) changed:" << endl; + cout << " Name: " << r->name().toStdString() << endl; + cout << " Canonical alias: " << r->canonicalAlias().toStdString() << endl; + }); + QObject::connect(r, &Room::aboutToAddNewMessages, [=] (Events evs) { + cout << "New events in room " << r->id().toStdString() << ":" << endl; + for (auto e: evs) + { + cout << e->originalJson().toStdString() << endl; + } + }); + }); + return app.exec(); +} |