Suggestions- Publishing data on a topic using Qt Slider

asked 2015-09-27 17:40:14 -0500

newbieros gravatar image

updated 2015-09-28 02:30:10 -0500

Hello All,

I am new to ROS, I need help regarding implementation of qt-slider in ros.

Can any one help me or give suggestions, thanks in advance.

I have qt source files: Please have a look:

MainWindow::MainWindow()
{
    slider = new QSlider(Qt::Horizontal);
    slider->setMinimum(0);
    slider->setMaximum(100);
    lineEdit = new QLineEdit();

    QObject::connect(slider, SIGNAL(valueChanged(int)),
                     this, SLOT(onValueChanged(int)));

    QVBoxLayout *layout = new QVBoxLayout();
    layout->addWidget(slider);
    layout->addWidget(lineEdit);

    QWidget *wrapper = new QWidget();
    wrapper->setLayout(layout);
    setCentralWidget(wrapper);
}

MainWindow::~MainWindow()
{
}

void MainWindow::onValueChanged(int value)
{
    int pos = slider->sliderPosition();
    QByteArray convertedValue = QByteArray::number(pos,16);
    QString m = QString(convertedValue);
    m= "0x"+m;
    QString id,len, canmsg;
    id="0x01 ";
    len="0x01 ";
    canmsg=id+len+m;
    lineEdit->setText(canmsg);
}

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    MainWindow mainWindow;
    mainWindow.show();
    return app.exec();
}

Can any one help me to publish this message(i mean 'canmsg') on topic(any). As discussed in qt ros, I made changes in cmakelist.txt. Thanks for reading.

edit retag flag offensive close merge delete

Comments

Please edit your question and include what you have tried yourself, what happened and why that didn't work. Otherwise we run the risk of suggesting things that you have already tried but didn't work for some reason.

gvdhoorn gravatar imagegvdhoorn ( 2015-09-28 02:20:54 -0500 )edit

Do you have a QNode class as well ? That's where you have to define and use your ROS publisher.

Cyril_J gravatar imageCyril_J ( 2015-11-20 04:56:25 -0500 )edit