Search code examples
c++qtsignals-slotsleap-motion

LeapMotion, Qt and signals


I'm working with a Leap and Qt on Mac OS X and I'm trying to emit a signal when the fingers position changed.

I'm (trying) to do this with QObject using :

class SampleListener : public Leap, public QObject{ 
     Q_Object

     class def }

but there is a problem with moc_SampleListener after compilation :

moc_SampleListener.cpp:94:18: error: no member named 'staticMetaObject' in 'Leap::Listener'
    { &Listener::staticMetaObject, qt_meta_stringdata_PhLeap.data,
       ~~~~~~~~~~^
moc_SampleListener.cpp:111:22: error: no member named 'qt_metacast' in 'Leap::Listener'
    return Listener::qt_metacast(_clname);
           ~~~~~~~~~~^
moc_SampleListener.cpp:116:21: error: no member named 'qt_metacall' in 'Leap::Listener'
    _id = Listener::qt_metacall(_c, _id, _a);
          ~~~~~~~~~~^

So I've 2 questions :

  1. Am I trying to emit signals the wrong way?
  2. Am I doing it the right way but with dummies errors?

Solution

  • Use the Q_OBJECT macro

    http://qt-project.org/doc/qt-5.0/qtcore/qobject.html#Q_OBJECT

    The Q_OBJECT macro must appear in the private section of a class definition that declares its own signals and slots or that uses other services provided by Qt's meta-object system.

    Oh, also, QObject must be the first inherited class