0

I am using QProcess in order to launch an application on my Ubuntu 18.04 OS. And after going through the documentation, I found that QProcess is the best approach. The problem I have is that I am trying to launch an application via QPushButton on a minimal GUI but it does not work and the error I get from the compiler is:

Launching LIDAR APP [EXEC] FINISHED: 0 QProcess::NormalExit [EXEC] buffered DATA: "roslaunch: no process found\n/home/emanuele/catkin_docking_ws/src/lidarboatsproject/start_lidar_deck_rosbag.sh: 5: /home/emanuele/catkin_docking_ws/src/lidarboatsproject/start_lidar_deck_rosbag.sh: roslaunch: not found\n"

This is the launch file I am trying to launch start_lidar_deck_rosbag.sh:

#!/bin/bash

killall roslaunch && sleep 10
cd /home/emanuele/catkin_docking_ws/
roslaunch lidar_deck lidar_deck_rosbag.launch &

Below the minimal GUI:

lau

mainwindow.h

class MainWindow : public QMainWindow
{
    Q_OBJECT
public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    void startLidar();

private slots:
    void on_launchLidarROSBtn_clicked();

private:
    Ui::MainWindow *ui;
    QProcess *executeROSLidarApp;

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    startLidar();
}

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

void MainWindow::startLidar()
{
    // Execution of the QProcess to make sure Lidar App Launcher opens:
    this->executeROSLidarApp = new QProcess(this);
    this->executeROSLidarApp->setProcessChannelMode(QProcess::MergedChannels);
    connect(this->executeROSLidarApp, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
            [script = this->executeROSLidarApp](int exitCode, QProcess::ExitStatus exitStatus){
            qDebug() << "[EXEC] FINISHED: " << exitCode << exitStatus;
            if(script->bytesAvailable() > 0) qDebug() << "[EXEC] buffered DATA:" << script->readAll();
    });
    connect(this->executeROSLidarApp, &QProcess::errorOccurred, [script = this->executeROSLidarApp](QProcess::ProcessError error) {
            qDebug() << "[EXEC] error on execution: " << error << script->errorString();
    });
}


void MainWindow::on_launchLidarROSBtn_clicked()
{
    qDebug() << "Launching LIDAR APP";
    this->executeROSLidarApp->start(QStringLiteral("/bin/sh"), QStringList() << QStringLiteral("/home/emanuele/catkin_docking_ws/src/lidarboatsproject/start_lidar_deck_rosbag.sh"));
}

In order to solve the problem I researched a lot a possible solution. I consulted this post and also this one. They were useful to set up the main chuck of the idea, but for some reasons I can't catch the process does not seems to start and I don't understand why the compiler is giving the error I mentioned above if I am sure that that file 100% exists.

proc

Please shed light and point to the right direction to solve this issue.

Emanuele
  • 2,194
  • 6
  • 32
  • 71
  • The process (`bin/sh`) is launching and executing the script. It seems as if the script itself is causing the problem. So, your c++ code is fine. – Waqar Jun 04 '20 at 20:49

1 Answers1

0

Your code is executing correctly, it is launching /bin/sh and executing the script and is finishing gracefully without errors. It is your script that's failing.

Here are somethings you can try:

  • Make sure the process roslaunch exists, thats the obvious error
  • Your script starts with #!bin/bash, but you are executing /bin/sh in QProcess. Change that to #!/bin/sh

PS:

You don't need to do

 QStringList() << QStringLiteral("/home/emanuele/catkin_docking_ws/src/lidarboatsproject/start_lidar_deck_rosbag.sh")

instead, you can just use the initializer_list syntax

 QStringList({"/home/emanuele/catkin_docking_ws/src/lidarboatsproject/start_lidar_deck_rosbag.sh"});
Waqar
  • 8,558
  • 4
  • 35
  • 43
  • Thanks for stopping by and reading the question. I tried both your solutions but unfortunately it still not work – Emanuele Jun 04 '20 at 22:06
  • regardless, the problem here isn't with `QProcess`, it is with the script. Maybe you should try running the script directly in the terminal to see if it executes correctly or not? – Waqar Jun 05 '20 at 05:55