I'm using ROS platform and want to publish a variable from publisher class. When I use this variable inside of QThread
it faces with below error:
error: invalid use of non-static data member ‘MainWindow::chatter_pub’ros::Publisher chatter_pub;
My code is like this:
mainWindow.h
class MainWindow : public QMainWindow {
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
class Thread : public QThread {
public:
void run();
};
private:
Ui::MainWindow *ui;
ros::NodeHandle nh_;
ros::Publisher chatter_pub;
Thread thread;
};
mainWindow.cpp
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
chatter_pub = nh_.advertise<visualization_msgs::Marker>("chatter", 10);
}
void MainWindow::on_open_cam_indoor_clicked()
{
thread.start();
}
void MainWindow::Thread::run()
{
while (true)
{
...
chatter_pub.publish(myVariableWantToSend);
...
}
}
The main question is how can I use publisher method inside of QThread
without any errors and problems. Thanks a lot...!
Aucun commentaire:
Enregistrer un commentaire