December 21, 2011

p-himik p-himik
Lab Rat
235 posts

Q_OBJECT in template class and order of slots


Since template classes cannot contain Q_OBJECT macro and i really need templates i wrote the code similar to this:

  1. class ObjectParent : public QObject
  2. {
  3.     Q_OBJECT
  4.     ...
  5. public slots:
  6.     void slot1(){...};
  7.     void slot2(){...};
  8. };
  10. template< typename T >
  11. class TemplateParent : public ObjectParent
  12. {
  13.     T t_;
  14.     ...
  15. };
  17. class TemplateArgument {...};
  19. class MyClass : public TemplateParent< TemplateArgument >
  20. {
  21.     Q_OBJECT
  22.     ...
  23. };

Then i connect some signals to slot1 and slot2 of MyClass instances. First compilations and launches – everything works smoothly. Today i got “no such slot: MyClass::slot2()”. Tried to add another “public slots” right before slot2() declaration, tried to do complete rebuild – nothing. Then i just swapped slot1() and slot2() declarations (and definitions since they are in the header too) and everything works again!

What was the reason for QObject::connect() didn’t find slot2() slot and why complete rebuilding did nothing where just swapping of two slots’ declarations did the thing?

1 reply

December 21, 2011

peppe peppe
Ant Farmer
1005 posts

If you put together a minimal testcase you could submit a bug report, although I’m not sure you’re in a supported case there (cf. moc limitations).


Software Engineer
KDAB (UK) Ltd., a KDAB Group company

  ‹‹ [SOLVED] QHostinfo: no such file or directory      How to render flash content/(html doc with flash content) using QWebView in windows OS ››

You must log in to post a reply. Not a member yet? Register here!