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:
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.
Please shed light and point to the right direction to solve this issue.
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:
roslaunch
exists, thats the obvious error#!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"});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.