I am trying to create an application that connects to my raspberry pi via ssh and lists the stuff in it’s home directory. The problem is that it says “process not started” and I don’t understand why the process won’t start.
//this button should start the ssh process
void MainWindow::on_connectButton_clicked()
{
//this is where the desired command is given to the application
QProcess process;
process.start("ssh -i /home/usr/ssh_key pi@pi_ip_address ls"); //command to be executed
//if-statement that checks wether the process has started
if (process.waitForStarted()) {
QMessageBox::information(this, "Info", "process started");
}
else{
QMessageBox::information(this, "Info", "process not started");
}
//reads the output of the command and errors
QString output = process.readAllStandardOutput();
QString error = process.readAllStandardError();
//puts the errors and output into messageBoxes
if (error.isEmpty()) {
QMessageBox::information(this, "Command output", output);
}
else {
QMessageBox::critical(this, "command error", error);
}
}
Here are the included libraries:
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include <QMessageBox>
#include <QProcess>
#include <string>
#include <QInputDialog>
#include <libssh2.h>
#include <QFile>
#include <libssh2_sftp.h>
I tried the program with commands like “ls”, “pwd” and “whoami” and they all worked, so I am quite confused. I also ran the ssh command in terminal and it worked. I am very new to this so any help and tips are welcome. Thank you in advance.
unknown_coder is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.