How to kill rosnode via Qt gui? (QProcess). Node hungs.

asked 2021-01-12 06:31:12 -0600

nikko gravatar image

updated 2021-01-19 01:15:34 -0600


I'm facing difficulties shutting down my rosnode that I run through my self made Qt (5) GUI utilizing its QProcess class. I have tried multiple ideas found from the internet, but for some reason none of them are working for me. My ROS is Melodic.

EDIT Since I did not get much attention here I also tried to find answers from Qt forums. I got some good tips, but the answer hasn't been found yet. This problem seems to be more about ROS than Qt, I think. I tested QProcess running and killing with gnome-calculator and it worked well. Here is the link for my post in Qt forums:

Here is a snippet from my code where I'm trying to kill my node after I have pushed a exit button. The node started inside QProcess is named as "point_collector". You can see some of my other tryings as comments in the code.

    if (resBtn != QMessageBox::Yes) {
} else {
    if (scanProcess->atEnd()){

        std::cout << "Scan process running. will be killed" << std::endl;
        QProcess killer;
        killer.start("kill -SIGINT " + QString::number(scanProcess->processId()));
        bool started = killer.waitForStarted();

        //std::cout <<started<<std::endl;
        //std::cout <<scanProcess->atEnd()<<std::endl;
        //killer.start("rosnode kill point_collector");

Here the code how I start the Qprocess:

 QString str = "rosrun point_collector collector "+ scantime->text()+" "+savepath->text()+" "+"livox/lidar"+" "+"livox_frame"+" "+"worksite";
    bool started = scanProcess->waitForStarted(-1);

For my point_collector I also tried to utilize the Custom SIGINT Handler like in the tutorial ( it did not make any difference.

The node shuts down normally in terminal though when I rosrun it ans "rosnode kill node" works also if I have started the node via QProcess. BUT If I have tried to kill() the node via QProcess, "rosnode kill node" in terminal does not work. Somehow the node gets jammed. "rosnode cleanup" seem to clean the node from nodelist.

For ROS launch file "kill -SIGINT processPID" worked fine but for a single node (that I run as node also) it didn't.

Any ideas how to solve this??

edit retag flag offensive close merge delete