Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Problem sending command in SSH connection using Qt-creator
Forum Updated to NodeBB v4.3 + New Features

Problem sending command in SSH connection using Qt-creator

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
sshconnection i
7 Posts 2 Posters 4.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • JanaJ Offline
    JanaJ Offline
    Jana
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • JanaJ Offline
        JanaJ Offline
        Jana
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What does acquire do ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • JanaJ Offline
            JanaJ Offline
            Jana
            wrote on last edited by
            #5

            "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 -69

            I 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...

            1 Reply Last reply
            0
            • JanaJ Offline
              JanaJ Offline
              Jana
              wrote on last edited by
              #6

              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 ;)

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                That's a good workaround. Are you using QProcess ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved