ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

How to add buttons to a customized RViz panel

asked 2019-06-18 05:32:24 -0500

RayROS gravatar image

updated 2019-06-18 09:18:34 -0500

Hello, I am sub-classing RViz to create a small customized panel. I found this and started doing this tutorial. However I was trying to implement a couple of buttons. I did using getNumViews() function available here. As I click on the button nothing happens and the view never changes. Is there something I am missing? Thanks for shedding light on this issues. Below the code:


public Q_SLOTS:
    void switchToTopView(QString viewName);
    void switchToSideView(QString viewName);

    QString sideView = "Side View";
    QString topView = "Top View";


MyViz::MyViz(QWidget *parent) : QWidget(parent)

// Setting up constructor

    QPushButton *topViewBtn = new QPushButton("Top View");
    QPushButton *sideViewBtn = new QPushButton("Side View");

    QGridLayout* control_layout = new QGridLayout();
    control_layout->addWidget(topViewBtn, 3, 0);
    control_layout->addWidget(sideViewBtn, 3, 1);

    // construct lay-out and render panels next to each other
    render_panel = new rviz::RenderPanel();

    connect(topViewBtn, SIGNAL(clicked()), this, SLOT(switchToTopView(QString("Top View"))));
    connect(sideViewBtn, SIGNAL(clicked()), this, SLOT(switchToSideView(QString("Side View"))));

// Other operations


void MyViz::switchToTopView(QString viewName)
    topView = viewName;
    view_man = manager->getViewManager();
    view_man->getViewAt(1)->getName() = topView;

void MyViz::switchToSideView(QString viewName)
    sideView = viewName;
    view_man = manager->getViewManager();
    view_man->getViewAt(2)->getName() = sideView;
edit retag flag offensive close merge delete


I have not looked into your problem in detail, but this:

view_man->getViewAt(1)->getName() == topView;

is a boolean expression, comparing topView to whatever is returned by view_man->getViewAt(1)->getName().

Did you mean to assign topView to view_man->getViewAt(1)->getName()? Then you'd have to remove a =.

gvdhoorn gravatar image gvdhoorn  ( 2019-06-18 08:40:37 -0500 )edit

Thanks gvdhoorn for taking the time to read the question. Yes your comment is right and I fixed it to the code but I now get the QObject::connect: No such slot MyViz::switchToTopView(QString("Top View")) error from compiler and don't understand why. And also QObject::connect: No such slot MyViz::switchToTopView(QString("Side View"))

RayROS gravatar image RayROS  ( 2019-06-18 09:06:12 -0500 )edit

I went through the official documentation about that and I thought that the SIGNAL and SLOT statement should have been correct. Am I missing something?

RayROS gravatar image RayROS  ( 2019-06-18 09:23:46 -0500 )edit

I've not looked at this at all, so I wouldn't be able to help you unfortunately.

gvdhoorn gravatar image gvdhoorn  ( 2019-06-18 10:27:19 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-06-30 10:15:38 -0500

RayROS gravatar image

I figured out the answer to this question and why there was no connection between SIGNAL and SLOT and wanted to share in case someone has my same problem. The small issue was the different notation between C++11 and C++17 and about my question the correct answer is the notation below:

QObject::connect( topViewBtn1, &QPushButton::clicked, [this](){
    switchToTopView(QString("Top View"));

As also explained here I hope this could be helpful for others.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-06-18 05:32:24 -0500

Seen: 1,034 times

Last updated: Jun 30 '19