ROS in Qt framework

//test.h
#include <ros/ros.h>
class Test:public QThread//must inherit from QThread
{
    Q_OBJECT
public:
    Test(ros::NodeHandle);
    ~Test();
public slots:
public:
    ros::NodeHandle m_ROSNode;
public:
    void run();
};
 
 
//test.cpp
#include "test.h"
Test::Test(ros::NodeHandle node):
    m_ROSNode(node)
{
    //initialization
    //connect slot functions
}

void Test::run()
{
    ros::spin();//must be ros::spin()
}

//main.cpp
#include <QtCore/QCoreApplication>
#include "test.h"
int main(int argc, char** argv)
{
    QCoreApplication a(argc, argv);
    ros::init(argc, argv, "Test");
    ros::NodeHandle node;
    Test test(node);
    test.start();
    return a.exec();
}


猜你喜欢

转载自blog.csdn.net/owldestiny/article/details/8445625