diff options
-rw-r--r-- | examples/qmc-example.cpp | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/examples/qmc-example.cpp b/examples/qmc-example.cpp index 36446255..7b45a785 100644 --- a/examples/qmc-example.cpp +++ b/examples/qmc-example.cpp @@ -4,12 +4,29 @@ #include "connection.h" #include "room.h" -int main(int argc, char* argv[]) +using namespace QMatrixClient; +using std::cout; +using std::endl; + +void onNewRoom(Room* r) { - using namespace QMatrixClient; - using std::cout; - using std::endl; + 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; + } + }); +} +int main(int argc, char* argv[]) +{ QCoreApplication app(argc, argv); if (argc < 2) return -1; @@ -24,20 +41,6 @@ int main(int argc, char* argv[]) 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; - } - }); - }); + QObject::connect(conn, &Connection::newRoom, onNewRoom); return app.exec(); } |