Hi, I am writing a tool to allowed call a function in the specified existing thread, I want to contribution it to Qt project, are you like?
We have such needs in many places, such as QQmlThreadPrivate::triggerMainEvent(https://github.com/qt/qtdeclarative/blob/dev/src/qml/qml/ftw/qqmlthread.cpp#L68). generally using a custom event to call the function in the event processing, but the code implemented in this way is not easy to read, maybe we can encapsulate a common interface to provide this function. I implemented a demo that allows us to use it like the following code (full code is at: https://github.com/zccrs/qt-demo/tree/main): int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); a. thread()->setObjectName("MainThread"); QThread testThread; testThread.setObjectName("TestThread"); testThread. start(); // Call In Test Thread auto future = QtConcurrent::run(&testThread, function); future. then(&a, [] () { qDebug() << QThread::currentThread(); // Main Thread }); return a.exec(); }
-- Development mailing list Development@qt-project.org https://lists.qt-project.org/listinfo/development