55 if (obj.thread () != QThread::currentThread ())
57 using namespace std::string_literals;
58 const auto& msg =
"binding to a QObject "s + obj.metaObject ()->className () +
59 " [" + obj.objectName ().toStdString () +
"] from a different thread";
60 throw std::runtime_error { msg };
63 thread_local std::unordered_map<QObject*, std::unique_ptr<CoroContext>> contexts;
64 auto& ctx = contexts [&obj];
67 ctx = std::make_unique<CoroContext> (obj);
69 QObject::connect (&obj,
74 if (!contexts.erase (&obj))
75 qCritical () <<
"could not find" << &obj <<
"in the contexts map — threading messed up?";
77 Qt::DirectConnection);
ContextDeadException(const QString &)
static CoroContext & Of(QObject &obj)
Returns the context tied to the lifetime of obj.