0

I'm using Qt 5.9.

I've a problem declaring slots with underscore style in particular when I name it with more then 2 underscores.For example with a void on_stop_treatment() slot, even I don't make a connection, I get QMetaObject::connectSlotsByName: No matching signal for on_stop_treatment().

Anyway, making a connection, even if I get the same message, the slot signal mechanism works. Removing the second underscore I get no error message and the mechanism works. (I also tried deleting the moc file and rebuild)

  • 1
    Possible duplicate of [QMetaObject::connectSlotsByName: No matching signal](https://stackoverflow.com/questions/24355023/qmetaobjectconnectslotsbyname-no-matching-signal) – eyllanesc Oct 09 '17 at 10:19
  • This is not a bug, moc to connect some slots created by Qt Designer uses the method [connectSlotsByName](http://doc.qt.io/qt-5/qmetaobject.html#connectSlotsByName), this method will try to connect any slot that has the format `on__`, and in your case your slot has that format so it is looking for and within your class – eyllanesc Oct 09 '17 at 10:22
  • But from i've understood from your answer i should get QMetaObject::connectSlotsByName: No matching signal for stop() and not QMetaObject::connectSlotsByName: No matching signal for on_stop_treatment() – Antonio Del Sannio Oct 09 '17 at 10:27
  • No, it will try to look for a hypothetical `treatment` signal on a hypothetical `stop` object – Rafalon Oct 09 '17 at 10:28

1 Answers1

3

Declaring your slot with the name on_stop_treatment will clash with the Qt feature called Signal/Slot Automatic Connections

Qt will detect this specific syntax for your slot, and will try to match stop with a QObject named stop and treatment with a signal of that name declared in the class of the QObject.

To achieve this, Qt uses internally QMetaObject::connectSlotsByName(this); to perform automatic signal/slot connections.

Antwane
  • 20,760
  • 7
  • 51
  • 84
  • This question is duplicated, there is no need to answer it. – eyllanesc Oct 09 '17 at 10:29
  • Possible duplicate of [QMetaObject::connectSlotsByName: No matching signal](https://stackoverflow.com/questions/24355023/qmetaobjectconnectslotsbyname-no-matching-signal) – eyllanesc Oct 09 '17 at 10:33
  • 1
    Nope, OP ask why he get this error when naming his slot like this. Other question from jhy ask why his signal/slot automatic connection doesn't work like he want. There is no duplication here – Antwane Oct 09 '17 at 10:41
  • Totally OT, but I love your avatar. Milkman Dan is really not appreciated enough at his job (or by Karen). – Some programmer dude Oct 09 '17 at 10:47