It was required to call the lambda on the signal, but not directly, but from the event queue. Trying to connect:

connect(model, &MyModel::modelReset, [this]() {}, Qt::QueuedConnection); 

The compiler starts swearing. How to win without the need to create a full-fledged method in the classroom?

Addition

Swears at the lack of a suitable method for connect() :

error: no matching function for call to 'MyClass :: connect (MyModel * &, void (QAbstractItemModel :: *) (QAbstractItemModel :: QPrivateSignal), MyClass :: myMethod () ::, Qt :: ConnectionType)' connect (model , & MyModel :: modelReset, this {}, Qt :: QueuedConnection);

  • And what swears, can you bring the output of the compiler? - Vladimir Gamalyan
  • And it seems that Qt::ConnectionType works only if the QObject inheritor is used. - Vladimir Gamalyan
  • @VladimirGamalian, updated the answer. My class MyClass is a successor to QAbstractItemModel and, accordingly, QObject . - alexis031182

1 answer 1

If you want to use the lambda and the event queue, then you need to specify the context in which the queue exists. You lack the argument in the call, it should be like this:

 connect(model, &MyModel::modelReset, context, [this]() {}, Qt::QueuedConnection); 

Where context is the successor of QObject (everything is exactly the same as in the case with the old syntax connect )

  • To me, thank you very much, very much helped out. In the trolls on the forum it is written that, they say, so nifiga is impossible , but it turns out you can. - alexis031182
  • @ alexis031182, where the moderator simply did not understand the question, the documentation just described such a case. And according to the logic of things, such a call should be possible; there is nothing extraordinary in such a need, it is a typical use. - ixSci
  • Why, I also thought that it should be possible (there was simply no need for a sabzhekte before), but I didn’t have it myself, I started looking for an answer, and the trolls had sadness. Thanks again. - alexis031182