The code below demonstrates how you should use the Listener
API correctly with Qt.
This code does not require to be run through moc
. I've also checked that it builds and runs with Leap SDK.
#include <QApplication>
#include <QLabel>
#include "leap.h"
class MyListener : public QObject, public Leap::Listener {
public:
virtual void onFrame(const Leap::Controller & ctl) {
Leap::Frame f = ctl.frame();
// This is a hack so that we avoid having to declare a signal and
// use moc generated code.
setObjectName(QString::number(f.id()));
// emits objectNameChanged(QString)
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MyListener listener;
Leap::Controller controller;
controller.addListener(listener);
QLabel frameLabel;
frameLabel.setMinimumSize(200, 50);
frameLabel.show();
frameLabel.connect(&listener, SIGNAL(objectNameChanged(QString)),
SLOT(setText(QString)));
int rc = a.exec();
controller.removeListener(listener);
return rc;
}