From 9af8b122516867c47dfdc7293b19eecd6f4f4eab Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 21 Mar 2017 12:45:29 +0900 Subject: Fixed to work with older MinGW At least MinGW 4.8 (bundled with Qt 5.2.1 for Windows) crashes with internal error on lambdas-in-lambdas. --- examples/qmc-example.cpp | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'examples') 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(); } -- cgit v1.2.3