连接 Leap 和 QT [英] Connecting Leap And QT Togther

查看:74
本文介绍了连接 Leap 和 QT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在互联网上长时间搜索后,我没有找到任何合理的解决方案,即:

after long long search over the internet i did not found any reason able solution to my problem which is that:

我有一个应用程序可以根据需要记录用户手指的移动,(当用户按下 r 时开始记录,当用户按下 s 时停止记录,

i have an application that record the user finger movement on demand, (when the user pressing r its start to record when the user press the s its stop the record,

直到现在我的应用程序都在控制台上,所以它可以完美地与跳跃运动一起工作,现在我们决定将应用程序移动到基于 GUI 的应用程序,我们选择了 QT 平台,我们将 GUI 与我们的解决方案集成,我们放置了两个按钮来代替按键,并连接事件.真正的问题是当我们想查看跳跃侦听器的 onFrame 回调捕获的内容时,我们注意到自从 QT 的主 GUI 被执行以来,跳跃的回调是如何阻塞或只是没有获得 CPU 时间(我不知道真正的问题),我们尝试了几种解决方案,例如使用从 QObject 继承的包装类和从那里开始一个线程,但它似乎没有任何影响.

till now i the application was on the console so it worked perfectly with leap motion, now we have decided to move the application to GUI based application, and we have chosen QT platform, we integrated the GUI with our solution , we have placed two push buttons to replace the key pressing , and connected the events. the real problem started when we wanted to see what was captured by the onFrame call back of the leap listener and we have noticed ever since the Main GUI of the QT is preformed the callbacks of the leap are some how blocked or just dont get cpu time(i dont know the real issue) , we tried several solutions like using a wrapper class that inherit from QObject and start a thread from there but it doesnt seem to effect anything.

这里是 main.cpp

here is the main.cpp

  int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    LeapClass::QLeapLis * smp = LeapClass::QLeapLis::get_instance();

    QThread * th =  smp->thread();
    //smp->moveToThread(th);
    th->start(QThread::HighPriority);


    w.show();

    return a.exec();
}

这里的 QLeapLis 是 Wrapper 类,它有一个启动设备的 run 方法,但仍然注意到发生了,我非常接近放弃 QT.

here the QLeapLis is the Wrapper class, that has a run method that start the device, but still noting happens, i am very close to give up on QT.

如果有人知道如何将这两者联系起来,我们将不胜感激

if someone knows how to connect those two we will be grateful

非常感谢.

推荐答案

下面的代码演示了如何在 Qt 中正确使用 Listener API.

The code below demonstrates how you should use the Listener API correctly with Qt.

此代码不需要通过moc运行.我还检查了它是否与 Leap SDK 一起构建和运行.

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;
}

这篇关于连接 Leap 和 QT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆