ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Creating Custom Rviz Panel with Qt

asked 2018-12-27 11:16:37 -0600

jbeck28 gravatar image

updated 2018-12-27 12:56:32 -0600

I've been trying to get a widget I made in qtCreator to work as an Rviz panel. I've had a lot of problems with inheritance. Specifically, in order for the definitions in my ui_mainwindow.h file to match the input argument defined in mainwindow, I need to inherit from QMainWindow, however, this and rviz::Panel both inherit from QObject, and so it is an ambiguous base.

The specific error which appears upon catkin_make, given the below code is as follows:

/home/rnd/catkin_ws/src/rviz_panel_test/src/mainwindow.cpp: In constructor ‘MainWindow::MainWindow(QWidget*)’:
/home/rnd/catkin_ws/src/rviz_panel_test/src/mainwindow.cpp:14:21: error: no matching function for call to ‘Ui::MainWindow::setupUi(MainWindow*)’
     ui->setupUi(this);
                     ^
In file included from /home/rnd/catkin_ws/src/rviz_panel_test/src/mainwindow.cpp:3:0:
/home/rnd/catkin_ws/build/rviz_panel_test/ui_mainwindow.h:37:10: note: candidate: void Ui_MainWindow::setupUi(QMainWindow*)
     void setupUi(QMainWindow *MainWindow)
          ^
/home/rnd/catkin_ws/build/rviz_panel_test/ui_mainwindow.h:37:10: note:   no known conversion for argument 1 from ‘MainWindow*’ to ‘QMainWindow*’

I'm running ROS Kinetic on Ubuntu 16.04

mainwindow.h: `

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#ifndef Q_MOC_RUN
# include <ros/ros.h>
# include <rviz/panel.h>
#endif
#include <QMainWindow>
#include <QWidget>
//#include "ui_mainwindow.h"
namespace Ui {
class MainWindow;
}
//namespace rviz_panel_test{
class MainWindow : public rviz::Panel // tried to inherit QMainWindow here as well.
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private Q_SLOTS:
    void on_pushButton_clicked();

private:
    Ui::MainWindow *ui;
};
//}
#endif // MAINWINDOW_H

mainwindow.cpp

    #include "ui_mainwindow.h"
#include <QFileDialog>
#include <rviz/panel.h>
#include <ros/ros.h>
#include "mainwindow.h"
#include <QMainWindow>
//namespace rviz_panel_test{
MainWindow::MainWindow(QWidget *parent) : //QMainWindow(parent),
    rviz::Panel(parent), 
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Open File"),tr("/home/rnd/catkin_ws/src/optimax_utils/toolpath"),tr("Txt Files (*.txt)"));
    ui->listWidget->addItems(fileNames);
}
//}
//#include "mainwindow.moc"
#include <pluginlib/class_list_macros.h>
PLUGINLIB_EXPORT_CLASS(MainWindow,rviz::Panel )

ui_mainwindow.h

    /********************************************************************************
** Form generated from reading UI file 'mainwindow.ui'
**
** Created by: Qt User Interface Compiler version 5.5.1
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/

#ifndef UI_MAINWINDOW_H
#define UI_MAINWINDOW_H

#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QListWidget>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QStatusBar>
#include <QtWidgets/QToolBar>
#include <QtWidgets/QWidget>

QT_BEGIN_NAMESPACE

class Ui_MainWindow
{
public:
    QWidget *centralWidget;
    QPushButton *pushButton;
    QListWidget *listWidget;
    QMenuBar *menuBar;
    QToolBar *mainToolBar;
    QStatusBar *statusBar;

    void setupUi(QMainWindow *MainWindow)
    {
        if (MainWindow->objectName().isEmpty())
            MainWindow->setObjectName(QStringLiteral("MainWindow"));
        MainWindow->resize(413, 305);
        centralWidget = new QWidget(MainWindow);
        centralWidget->setObjectName(QStringLiteral("centralWidget"));
        pushButton = new QPushButton(centralWidget);
        pushButton->setObjectName(QStringLiteral("pushButton"));
        pushButton->setGeometry(QRect(140, 200, 121, 25));
        listWidget = new QListWidget(centralWidget);
        listWidget->setObjectName(QStringLiteral("listWidget"));
        listWidget->setGeometry(QRect(25, 0, 361, 192));
        MainWindow->setCentralWidget(centralWidget);
        menuBar = new QMenuBar(MainWindow);
        menuBar->setObjectName(QStringLiteral("menuBar"));
        menuBar->setGeometry(QRect(0, 0, 413, 22));
        MainWindow->setMenuBar(menuBar);
        mainToolBar = new QToolBar(MainWindow);
        mainToolBar->setObjectName(QStringLiteral("mainToolBar"));
        MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar);
        statusBar = new ...
(more)
edit retag flag offensive close merge delete

Comments

Not an answer, but may help: InstitutMaupertuis/simple_rviz_plugin.

gvdhoorn gravatar image gvdhoorn  ( 2018-12-27 13:31:49 -0600 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2020-12-13 07:36:47 -0600

You may want to add a bracket after the initialization.

ui(new Ui::MainWindow())

You can also refer to this repository: https://github.com/BruceChanJianLe/rv...

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-12-27 11:16:37 -0600

Seen: 1,327 times

Last updated: Dec 27 '18