[英]QProcess fails to start a process : no process found
I am using QProcess
in order to launch an application on my Ubuntu 18.04
OS.我正在使用QProcess
在我的Ubuntu 18.04
操作系统上启动应用程序。 And after going through the documentation, I found that QProcess
is the best approach.在浏览了文档之后,我发现QProcess
是最好的方法。 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:我遇到的问题是我试图在最小的 GUI 上通过QPushButton
启动应用程序,但它不起作用,我从编译器得到的错误是:
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"启动 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: 未找到\n"
This is the launch file I am trying to launch start_lidar_deck_rosbag.sh
:这是我试图启动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:在最小的 GUI 下方:
mainwindow.h主窗口.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主窗口.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.它们对于设置这个想法的主要部分很有用,但由于某些原因,我无法捕捉到这个过程似乎没有开始,我不明白为什么编译器会给出我上面提到的错误,如果我确定的话该文件100%存在。
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.您的代码正在正确执行,它正在启动/bin/sh
并执行脚本,并且正在优雅地完成而没有错误。 It is your script that's failing.是你的脚本失败了。
Here are somethings you can try:您可以尝试以下方法:
roslaunch
exists, thats the obvious error确保进程roslaunch
存在,这是明显的错误#!bin/bash
, but you are executing /bin/sh
in QProcess
.您的脚本以#!bin/bash
开头,但您在QProcess
中执行/bin/sh
。 Change that to #!/bin/sh
将其更改为#!/bin/sh
PS: 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相反,您可以只使用 initializer_list 语法
QStringList({"/home/emanuele/catkin_docking_ws/src/lidarboatsproject/start_lidar_deck_rosbag.sh"});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.