QT订阅ROS2信息并发布
-
系统ubuntu22.04 ROS2 Humble
大佬们,就是我想结合QT5写一个可以订阅ros2节点信息并显示的界面,我将功能包写成这样
.
├── CMakeLists.txt
├── CMakeLists.txt.user
├── include
│ └── ros2_qt_display
│ ├── mainwindow.h
│ └── rclcomm.h
├── package.xml
├── src
│ ├── main.cpp
│ ├── mainwindow.cpp
│ └── rclcomm.cpp
└── ui
└── mainwindow.ui
我的mainwindow.h:#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include "rclcomm.h" #include <iostream> QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = nullptr); ~MainWindow(); private: Ui::MainWindow *ui; rclcomm *commNode; public slots: void on_getimuyaw(QString); void on_getimupitch(QString); void on_getimuroll(QString); void on_getimulat(QString); void on_getimulon(QString); void on_getimualt(QString); void on_getimuxangvel(QString); void on_getimuyangvel(QString); void on_getimuzangvel(QString); void on_getimuxspef(QString); void on_getimuyspef(QString); void on_getimuzspef(QString); void on_getimunvel(QString); void on_getimuevel(QString); void on_getimuvelerr(QString); void on_pushButton02_clicked(); void on_pushButton01_clicked(); }; #endif // MAINWINDOW_H
然后我在mainwindow.cpp中调用这些:
#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); connect(ui->pushButton01,SIGNAL(clicked(bool)),this,SLOT(on_pushButton01_clicked())); connect(ui->pushButton02,SIGNAL(clicked(bool)),this,SLOT(on_pushButton02_clicked())); commNode=new rclcomm(); connect(commNode,SIGNAL(getimuyaw(QString)),this,SLOT(on_getimuyaw(QString))); connect(commNode,SIGNAL(getimupitch(QString)),this,SLOT(on_getimupitch(QString))); connect(commNode,SIGNAL(getimuroll(QString)),this,SLOT(on_getimuroll(QString))); connect(commNode,SIGNAL(getimulat(QString)),this,SLOT(on_getimulat(QString))); connect(commNode,SIGNAL(getimulon(QString)),this,SLOT(on_getimulon(QString))); connect(commNode,SIGNAL(getimualt(QString)),this,SLOT(on_getimualt(QString))); connect(commNode,SIGNAL(getimuxangvel(QString)),this,SLOT(on_getimuxangvel(QString))); connect(commNode,SIGNAL(getimuyangvel(QString)),this,SLOT(on_getimuyangvel(QString))); connect(commNode,SIGNAL(getimuzangvel(QString)),this,SLOT(on_getimuzangvel(QString))); connect(commNode,SIGNAL(getimuxspef(QString)),this,SLOT(on_getimuxspef(QString))); connect(commNode,SIGNAL(getimuyspef(QString)),this,SLOT(on_getimuyspef(QString))); connect(commNode,SIGNAL(getimuzspef(QString)),this,SLOT(on_getimuzspef(QString))); connect(commNode,SIGNAL(getimunvel(QString)),this,SLOT(on_getimunvel(QString))); connect(commNode,SIGNAL(getimuevel(QString)),this,SLOT(on_getimuevel(QString))); connect(commNode,SIGNAL(getimuvelerr(QString)),this,SLOT(on_getimuvelerr(QString))); } void MainWindow::on_getimuyaw(QString yaw){ ui->textEdit_1->clear(); ui->textEdit_1->setText(yaw); } void MainWindow::on_getimupitch(QString pitch){ ui->textEdit_2->clear(); ui->textEdit_2->setText(pitch); } void MainWindow::on_getimuroll(QString roll){ ui->textEdit_3->clear(); ui->textEdit_3->setText(roll); } void MainWindow::on_getimulat(QString lat){ ui->textEdit_4->clear(); ui->textEdit_4->setText(lat); } void MainWindow::on_getimulon(QString lon){ ui->textEdit_5->clear(); ui->textEdit_5->setText(lon); } void MainWindow::on_getimualt(QString alt){ ui->textEdit_6->clear(); ui->textEdit_6->setText(alt); } void MainWindow::on_getimuxangvel(QString xangvel){ ui->textEdit_7->clear(); ui->textEdit_7->setText(xangvel); } void MainWindow::on_getimuyangvel(QString yangvel){ ui->textEdit_8->clear(); ui->textEdit_8->setText(yangvel); } void MainWindow::on_getimuzangvel(QString zangvel){ ui->textEdit_9->clear(); ui->textEdit_9->setText(zangvel); } void MainWindow::on_getimuxspef(QString xspef){ ui->textEdit_10->clear(); ui->textEdit_10->setText(xspef); } void MainWindow::on_getimuyspef(QString yspef){ ui->textEdit_11->clear(); ui->textEdit_11->setText(yspef); } void MainWindow::on_getimuzspef(QString zspef){ ui->textEdit_12->clear(); ui->textEdit_12->setText(zspef); } void MainWindow::on_getimunvel(QString nvel){ ui->textEdit_13->clear(); ui->textEdit_13->setText(nvel); } void MainWindow::on_getimuevel(QString evel){ ui->textEdit_15->clear(); ui->textEdit_15->setText(evel); } void MainWindow::on_getimuvelerr(QString velerr){ ui->textEdit_15->clear(); ui->textEdit_15->setText(velerr); } void MainWindow::on_pushButton01_clicked() { commNode->start(); } void MainWindow::on_pushButton02_clicked() { } MainWindow::~MainWindow() { delete ui; }
我的终端始终爆出下面的问题:
--- stderr: ros2_qt_display /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/Scrt1.o: in function `_start': (.text+0x1b): undefined reference to `main' /usr/bin/ld: CMakeFiles/ros2_qt_display.dir/include/ros2_qt_display/moc_mainwindow.cpp.o: in function `MainWindow::qt_static_metacall(QObject*, QMetaObject::Call, int, void**)': moc_mainwindow.cpp:(.text+0x93): undefined reference to `MainWindow::on_getimuyaw(QString)' /usr/bin/ld: moc_mainwindow.cpp:(.text+0xd1): undefined reference to `MainWindow::on_getimupitch(QString)' /usr/bin/ld: moc_mainwindow.cpp:(.text+0x10f): undefined reference to `MainWindow::on_getimuroll(QString)' /usr/bin/ld: moc_mainwindow.cpp:(.text+0x14d): undefined reference to `MainWindow::on_getimulat(QString)' /usr/bin/ld: moc_mainwindow.cpp:(.text+0x18b): undefined reference to `MainWindow::on_getimulon(QString)' /usr/bin/ld: moc_mainwindow.cpp:(.text+0x1c9): undefined reference to `MainWindow::on_getimualt(QString)' /usr/bin/ld: moc_mainwindow.cpp:(.text+0x207): undefined reference to `MainWindow::on_getimuxangvel(QString)' /usr/bin/ld: moc_mainwindow.cpp:(.text+0x245): undefined reference to `MainWindow::on_getimuyangvel(QString)' /usr/bin/ld: moc_mainwindow.cpp:(.text+0x283): undefined reference to `MainWindow::on_getimuzangvel(QString)' /usr/bin/ld: moc_mainwindow.cpp:(.text+0x2c1): undefined reference to `MainWindow::on_getimuxspef(QString)' /usr/bin/ld: moc_mainwindow.cpp:(.text+0x2ff): undefined reference to `MainWindow::on_getimuyspef(QString)' /usr/bin/ld: moc_mainwindow.cpp:(.text+0x33d): undefined reference to `MainWindow::on_getimuzspef(QString)' /usr/bin/ld: moc_mainwindow.cpp:(.text+0x37b): undefined reference to `MainWindow::on_getimunvel(QString)' /usr/bin/ld: moc_mainwindow.cpp:(.text+0x3b9): undefined reference to `MainWindow::on_getimuevel(QString)' /usr/bin/ld: moc_mainwindow.cpp:(.text+0x3f4): undefined reference to `MainWindow::on_getimuvelerr(QString)' /usr/bin/ld: moc_mainwindow.cpp:(.text+0x40e): undefined reference to `MainWindow::on_pushButton02_clicked()' /usr/bin/ld: moc_mainwindow.cpp:(.text+0x41c): undefined reference to `MainWindow::on_pushButton01_clicked()' /usr/bin/ld: CMakeFiles/ros2_qt_display.dir/include/ros2_qt_display/moc_mainwindow.cpp.o:(.data.rel.ro._ZTV10MainWindow[_ZTV10MainWindow]+0x28): undefined reference to `MainWindow::~MainWindow()' /usr/bin/ld: CMakeFiles/ros2_qt_display.dir/include/ros2_qt_display/moc_mainwindow.cpp.o:(.data.rel.ro._ZTV10MainWindow[_ZTV10MainWindow]+0x30): undefined reference to `MainWindow::~MainWindow()' /usr/bin/ld: CMakeFiles/ros2_qt_display.dir/include/ros2_qt_display/moc_mainwindow.cpp.o:(.data.rel.ro._ZTV10MainWindow[_ZTV10MainWindow]+0x1c8): undefined reference to `non-virtual thunk to MainWindow::~MainWindow()' /usr/bin/ld: CMakeFiles/ros2_qt_display.dir/include/ros2_qt_display/moc_mainwindow.cpp.o:(.data.rel.ro._ZTV10MainWindow[_ZTV10MainWindow]+0x1d0): undefined reference to `non-virtual thunk to MainWindow::~MainWindow()' /usr/bin/ld: CMakeFiles/ros2_qt_display.dir/include/ros2_qt_display/moc_rclcomm.cpp.o:(.data.rel.ro._ZTV7rclcomm[_ZTV7rclcomm]+0x70): undefined reference to `rclcomm::run()' collect2: error: ld returned 1 exit status gmake[2]: *** [CMakeFiles/ros2_qt_display.dir/build.make:208:ros2_qt_display] 错误 1 gmake[1]: *** [CMakeFiles/Makefile2:137:CMakeFiles/ros2_qt_display.dir/all] 错误 2 gmake: *** [Makefile:146:all] 错误 2 ---
请问这是怎么回事呢,我用的VScode,请各位大佬提醒一下,谢谢