Answer the question
In order to leave comments, you need to log in
Qt: How does emit work and under what conditions does it go into multi-threaded mode?
Here we are in the thread constructor (which, of course, is executed from the main thread) we write:
MyThread::MyThread() : mainControl(откуда-то возьмём)
{
connect(this, MyThread::doSomething, mainControl->asQobject(), [this]() {
mainControl->doSomething();
});
}
void MyThread::run()
{
emit doSomething();
}
Answer the question
In order to leave comments, you need to log in
1) Look at the last argument of the connect method - this is the answer to your question ( https://doc.qt.io/qt-5/qobject.html#connect-5 )
2) The question is not very clear. The lambda in the connect method works like a regular lambda.
Here *almost* everything is written about multithreading in Qt: https://wiki.qt.io/Threads_Events_QObjects
Here about lambdas: en.cppreference.com/w/cpp/language/lambda
And yes, your code will not compile for many reasons . For example, like this: *this cannot be written before the 17th standard.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question