[Interest] Signal/Slot connection fails, even though QMetaObject::activate is called

Jonathan Purol contact at folling.de
Fri Feb 7 23:43:54 CET 2020


Hello everyone,

I have a QMainWindow subclass called `text_editor` with a function 
`save` which looks as follows:
```cpp
void text_editor::save() {

     _textbox->document()->setModified(false);
     _textbox->setFocus();

     emit saved();

}
```

I now connect to that slot in another class like this:
```cpp
_information_editor = new text_editor{this};

connect(
     _information_editor,
     &text_editor::saved,
     this,
     [=]() {
         std::cout << "hello\n";
     }
);

```

I have verified that the signal is emitted, in fact, the method 
generated by the moc:
```cpp
// SIGNAL 0
void text_editor::saved()
{
     QMetaObject::activate(this, &staticMetaObject, 0, nullptr);
}
```
is definitely called (verified with gdb and some other debugging 
shenenigans).
In addition, the connection object returned by `connect` is valid, as 
verified by its implicit bool-cast operator.
However, "hello" is never printed. I suspected this could be because 
`text_editor` inherits from `QMainWindow` and could have a different 
thread affinity, so I tried the following things:

1. Move the editor to the same thread as the object which establishes 
the connection
2. Use a QueuedConnection
3. Connect to the slot from WITHIN the text editor itself, making sure 
that we are 100% on the same slot

and none of them worked.
Just for clarification, the print of "hello" is only an example, so even 
if there was some issue with that, I would have detected it, the actual 
code is of course different.

I'm really out of luck here, and would appreciate any help.

Sincerely,
Folling



More information about the Interest mailing list