0
$\begingroup$

Rosanswers logo

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:

myviz.h

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

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

myviz.cpp

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->getNumViews();
    view_man->getViewAt(1)->getName() = topView;
    view_man->setCurrentFrom(view_man->getViewAt(1));
}

void MyViz::switchToSideView(QString viewName)
{
    sideView = viewName;
    view_man = manager->getViewManager();
    view_man->getNumViews();
    view_man->getViewAt(2)->getName() = sideView;
    view_man->setCurrentFrom(view_man->getViewAt(2));
}

Originally posted by RayROS on ROS Answers with karma: 108 on 2019-06-18

Post score: 0


Original comments

Comment by gvdhoorn on 2019-06-18:
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 =.

Comment by RayROS on 2019-06-18:
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"))

Comment by RayROS on 2019-06-18:
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?

Comment by gvdhoorn on 2019-06-18:
I've not looked at this at all, so I wouldn't be able to help you unfortunately.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by RayROS with karma: 108 on 2019-06-30

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.