Problem sending command in SSH connection using Qt-creator
-
wrote on 18 May 2016, 10:47 last edited by
Hi,
I'm a beginner in Qt and this is my first post here.
I'm trying to set up a ssh connection to a Red Pitaya using the SshConnection integrated in the Qt Creator library. I followed this post and actually everything works except the last step. The command is not sent or not received, I don't know.
There are no error messages, but the " closed (int exitStatus) " signal of the remoteProcess is directly sent after channel is started. exitStatus is 2, but I couldn't find, what is meant by that.My operating system is Ubuntu 14.04 and connecting via Terminal and ssh works perfectly. But I would like to start a program on the Red Pitaya directly in my Qt-Programm.
Has anyone a idea what's the problem here?
Thanks in advance!
Jana -
Hi and welcome to devnet,
Something's not clear: are you trying to start a remote program from your application and failing or is starting your application on the device failing from Qt Creator ?
-
wrote on 19 May 2016, 09:43 last edited by
Thanks for your reply. Sorry, for not describing clearly. I want to start a program on my remote device from within my Qt-application. Right now, I use Putty, connect to my device using SSH, type the command, press enter and the remote program starts. I would like to do the same from within my Qt-application.
Here's the class:
#ifndef RECEIVER_H #define RECEIVER_H #include <QWidget> #include "sshconnection.h" #include "sshremoteprocess.h" #include "ssherrors.h" class Receiver : public QWidget { Q_OBJECT public: Receiver(QWidget *parent = 0); private slots: void ssh_connected(); void onChannelStarted(); void readyReadStandardOutput(); void ssh_con(); void info(int exitStatus); void onConnectionError(QSsh::SshError); private: QSsh::SshRemoteProcess::Ptr remoteProc; QSsh::SshConnection *connection; }; #endif
#include <QDebug> #include "receiver.h" #define CALIB_DC_OFFSET 2000 Receiver::Receiver(QWidget *parent) : QWidget(parent) { statusLabel = new QLabel(tr("Listening for broadcasted messages")); statusLabel->setWordWrap(true); quitButton = new QPushButton(tr("&Quit")); connect(quitButton, SIGNAL(clicked()), this, SLOT(ssh_con())); QHBoxLayout *buttonLayout = new QHBoxLayout; buttonLayout->addStretch(1); buttonLayout->addWidget(quitButton); buttonLayout->addStretch(1); } void Receiver::ssh_con(){ QSsh::SshConnectionParameters parameters; parameters.host = IP; parameters.userName = user; parameters.password = password; parameters.timeout = 20; parameters.authenticationType = QSsh::SshConnectionParameters::AuthenticationTypePassword; parameters.port = 22; connection = new QSsh::SshConnection(parameters, this); connect( connection, SIGNAL(connected()), this, SLOT (ssh_connected())); connect(connection, SIGNAL(error(QSsh::SshError)), SLOT(onConnectionError(QSsh::SshError))); connection->connectToHost(); } void Receiver::onConnectionError(QSsh::SshError){ qDebug() << "Com: Connection error" << connection->errorString(); } void Receiver::ssh_connected(){ qDebug() << "ssh connected"; const QByteArray command ("acquire 10 1024"); // remoteProc = connection->createRemoteProcess(command); if(remoteProc){ connect(remoteProc.data(), SIGNAL (started()), SLOT (onChannelStarted())); connect(remoteProc.data(), SIGNAL(readyReadStandardOutput()), SLOT(readyReadStandardOutput())); connect(remoteProc.data(), SIGNAL(closed(int)), this, SLOT(info(int))); remoteProc->start(); } } void Receiver::info(int exitStatus){ qDebug() << "Session closed " << exitStatus; } void Receiver::onChannelStarted(){ qDebug() << "Channel started"; qDebug() << "RemoteProc is running: " << remoteProc->isRunning(); } void Receiver::readyReadStandardOutput(){ qDebug() << "OUTPUT: " << remoteProc->readAll(); }
I run it, and output is:
ssh connected
Channel started
remoteProc is running: true
Session closed 2 -
What does acquire do ?
-
wrote on 20 May 2016, 08:02 last edited by
"Acquire" is a program on the Red Pitaya that measures and returns voltage values. "Acquire 10 1024" should give an output of 10 rows and two columns of numbers, for example:
-163 -69
-164 -70
-163 -70
-163 -70
-162 -69
-164 -70
-165 -71
-163 -70
-163 -70
-163 -69I also tried "ls" and "ll" as a command, but it's the same debug-output.
I don't understand why a normal ssh-connection works, but using the qt-lib doesn't...
-
wrote on 6 Jun 2016, 11:00 last edited by
I did it differently now and wrote a small script using sshpass to open the connection and send the command. In my Qt program I just start the script. It takes a bit, but it's ok ;)
-
That's a good workaround. Are you using QProcess ?