Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to Execute SCP command to transfer files to a target machine
Forum Updated to NodeBB v4.3 + New Features

How to Execute SCP command to transfer files to a target machine

Scheduled Pinned Locked Moved Unsolved General and Desktop
35 Posts 6 Posters 14.9k Views 2 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.
  • M Offline
    M Offline
    moyin
    wrote on last edited by
    #1

    Actually i tried by taking ip, ssh_username, and sshh_password as input from GUI input.
    QProcess OProcess ;
    QString Command = "scp" ; //Contains the command to be executed
    QStringList params;
    params.append("/home/span51/Desktop/readme.txt");
    params.append("username@laptop:Desktop/" ); OProcess.start("scp",params,QIODevice::ReadWrite); //Starts execution of command

    jsulmJ 1 Reply Last reply
    0
    • M Offline
      M Offline
      mostefa
      wrote on last edited by mostefa
      #2

      Hi @moyin

      What is exactly your problem?

      Just as observation i think that according to your code, using startDetached is more appropriate than start

      Just replace this line:

      OProcess.start("scp",params,QIODevice::ReadWrite); //Starts execution of command
      

      to

      OProcess.startDetached("scp",params); //Starts execution of command
      
      1 Reply Last reply
      0
      • M moyin

        Actually i tried by taking ip, ssh_username, and sshh_password as input from GUI input.
        QProcess OProcess ;
        QString Command = "scp" ; //Contains the command to be executed
        QStringList params;
        params.append("/home/span51/Desktop/readme.txt");
        params.append("username@laptop:Desktop/" ); OProcess.start("scp",params,QIODevice::ReadWrite); //Starts execution of command

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @moyin said in How to Execute SCP command to transfer files to a target machine:

        username@laptop:Desktop/

        this path is invalid. You probably mean

        username@laptop:/home/username/Desktop/
        

        Also connect a slot to http://doc.qt.io/qt-5/qprocess.html#errorOccurred signal to get more information. And read the stdout and stderr of the process to see what it says.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        M 1 Reply Last reply
        1
        • jsulmJ jsulm

          @moyin said in How to Execute SCP command to transfer files to a target machine:

          username@laptop:Desktop/

          this path is invalid. You probably mean

          username@laptop:/home/username/Desktop/
          

          Also connect a slot to http://doc.qt.io/qt-5/qprocess.html#errorOccurred signal to get more information. And read the stdout and stderr of the process to see what it says.

          M Offline
          M Offline
          moyin
          wrote on last edited by
          #4

          @jsulm i need to redirect stdOut and stdError to a textedit.
          i tried this but not succeed.

          proc.startDetached(command,params,QIODevice::ReadWrite) ;

          QString StdOut      =   proc.readAllStandardOutput();  //Reads standard output
          QString StdError    =   proc.readAllStandardError();   //Reads standard error
          
          ui->textEdit_Standard_output->setText(StdOut);
          ui->textEdit_Standard_output->setText(StdError);
          
          jsulmJ 1 Reply Last reply
          0
          • M moyin

            @jsulm i need to redirect stdOut and stdError to a textedit.
            i tried this but not succeed.

            proc.startDetached(command,params,QIODevice::ReadWrite) ;

            QString StdOut      =   proc.readAllStandardOutput();  //Reads standard output
            QString StdError    =   proc.readAllStandardError();   //Reads standard error
            
            ui->textEdit_Standard_output->setText(StdOut);
            ui->textEdit_Standard_output->setText(StdError);
            
            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @moyin This is not how it works. You need to connect a slot to http://doc.qt.io/qt-5/qprocess.html#readyReadStandardError and http://doc.qt.io/qt-5/qprocess.html#readyReadStandardOutput signals and read both there.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            M 1 Reply Last reply
            2
            • jsulmJ jsulm

              @moyin This is not how it works. You need to connect a slot to http://doc.qt.io/qt-5/qprocess.html#readyReadStandardError and http://doc.qt.io/qt-5/qprocess.html#readyReadStandardOutput signals and read both there.

              M Offline
              M Offline
              moyin
              wrote on last edited by
              #6

              @jsulm can't i use

              OProcess.start("scp",params,QIODevice::ReadWrite); //Starts execution of command
              instead??

              jsulmJ 1 Reply Last reply
              0
              • M moyin

                @jsulm can't i use

                OProcess.start("scp",params,QIODevice::ReadWrite); //Starts execution of command
                instead??

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @moyin I don't understand what you mean. You need first to start the process, so yes you need to call start. Then, if you want to get stdout and stderr output of that process you need to connect a slot to those two signals I mentioned (you need the signal because you do not know when you will get output from the process, so you cannot just call readAllStandardOutput() at some random point).

                // Make process a class member because you need it in the slot bellow and because it would be deleted as soon
                // as it gets out of scope!
                class MainWindow
                {
                private:
                    QProcess process;
                }
                ...
                QString command = "scp" ; //Contains the command to be executed
                QStringList params;
                params.append("/home/span51/Desktop/readme.txt");
                params.append("username@laptop:Desktop/" ); // FIX THE PATH HERE AS IT IS INVALID!
                connect(process, SIGNAL(readyReadStandardError(), this, SLOT(readOutput()));
                connect(process, SIGNAL(readyReadStandardOutput(), this, SLOT(readOutput()));
                process.start(command, params, QIODevice::ReadWrite); //Starts execution of command
                ...
                void MainWindow::readOutput()
                {
                    QString StdOut proc.readAllStandardOutput();  //Reads standard output
                    QString StdError    =   proc.readAllStandardError();
                    ui->textEdit_Standard_output->setText(StdOut);
                    ui->textEdit_Standard_output->setText(StdError);
                }
                

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                M 1 Reply Last reply
                3
                • jsulmJ jsulm

                  @moyin I don't understand what you mean. You need first to start the process, so yes you need to call start. Then, if you want to get stdout and stderr output of that process you need to connect a slot to those two signals I mentioned (you need the signal because you do not know when you will get output from the process, so you cannot just call readAllStandardOutput() at some random point).

                  // Make process a class member because you need it in the slot bellow and because it would be deleted as soon
                  // as it gets out of scope!
                  class MainWindow
                  {
                  private:
                      QProcess process;
                  }
                  ...
                  QString command = "scp" ; //Contains the command to be executed
                  QStringList params;
                  params.append("/home/span51/Desktop/readme.txt");
                  params.append("username@laptop:Desktop/" ); // FIX THE PATH HERE AS IT IS INVALID!
                  connect(process, SIGNAL(readyReadStandardError(), this, SLOT(readOutput()));
                  connect(process, SIGNAL(readyReadStandardOutput(), this, SLOT(readOutput()));
                  process.start(command, params, QIODevice::ReadWrite); //Starts execution of command
                  ...
                  void MainWindow::readOutput()
                  {
                      QString StdOut proc.readAllStandardOutput();  //Reads standard output
                      QString StdError    =   proc.readAllStandardError();
                      ui->textEdit_Standard_output->setText(StdOut);
                      ui->textEdit_Standard_output->setText(StdError);
                  }
                  
                  M Offline
                  M Offline
                  moyin
                  wrote on last edited by
                  #8

                  @jsulm where u emitting the signal here??

                  jsulmJ 1 Reply Last reply
                  0
                  • M moyin

                    @jsulm where u emitting the signal here??

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @moyin QProcess instance (process) is emitting the signal, not you. I already posted links to documentation, you should read it...

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    M 1 Reply Last reply
                    3
                    • jsulmJ jsulm

                      @moyin QProcess instance (process) is emitting the signal, not you. I already posted links to documentation, you should read it...

                      M Offline
                      M Offline
                      moyin
                      wrote on last edited by
                      #10

                      @jsulm

                      #include "transfer.h"
                      #include "ui_transfer.h"
                      #include <sstream>
                      #include <QProcess>
                      #include <iostream>
                      #include <QDebug>
                      #include <QFileDialog>
                      #include <QtWidgets>

                      Transfer::Transfer(QWidget *parent) :
                      QDialog(parent),
                      ui(new Ui::Transfer)
                      {
                      ui->setupUi(this);
                      }

                      Transfer::~Transfer()
                      {
                      delete ui;
                      }

                      void Transfer::on_pushButton_Go_clicked()
                      { proc = new QProcess() ;
                      QString command = "scp" ;
                      QString ip = ui->lineEdit_IP_Address->text() ;
                      QString username = ui->lineEdit_SSH_username->text() ;
                      QString dest_path = ui->lineEdit_TransferToTarget_DestinationFolder->text() ;
                      QString source_path = ui->lineEdit_TransferToTarget_SourcePath->text() ;
                      std::stringstream s ;
                      s << username.toStdString() << "@" << ip.toStdString() << ":" << dest_path.toStdString();
                      std::cout << s.str() << std::endl ;
                      QStringList params ;
                      params.append(source_path) ;
                      params.append(QString::fromStdString(s.str())) ;
                      qDebug() << params ;
                      // params.append("/home/span51/Desktop/readme.txt");
                      // params.append("spanidea@192.168.1.26:/home/spanidea/test" );
                      connect(this, SIGNAL(readyReadStandardError()), this, SLOT(readOutput()));
                      connect(this, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput()));
                      proc->startDetached(command,params) ;

                      /* QString StdOut = proc.readAllStandardOutput(); //Reads standard output
                      QString StdError = proc.readAllStandardError(); //Reads standard error
                      std::cout<<"\n Printing the standard output..........\n";
                      std::cout<<endl<<StdOut.toStdString();
                      std::cout<<"\n Printing the standard error..........\n";
                      std::cout<<endl<<StdError.toStdString();
                      */
                      }

                      void Transfer::on_pushButton_choosefile_transferTotarget_clicked()
                      {
                      QString filepath = QFileDialog::getOpenFileName(this, tr("Transfer file"), "/home","Config_Files(*.c)") ;
                      ui->lineEdit_TransferToTarget_SourcePath->setText(filepath);
                      }

                      void Transfer::on_pushButton_Std_output_clear_clicked()
                      {
                      ui->textEdit_Standard_output->clear() ;
                      }

                      void Transfer::on_checkBox_Show_Password_clicked(bool checked)
                      {
                      if (checked)
                      ui->lineEdit_SSH_password->setEchoMode(QLineEdit::Normal);
                      else
                      ui->lineEdit_SSH_password->setEchoMode(QLineEdit::Password);
                      }

                      void Transfer::readOutput()
                      {
                      QString StdOut = proc->readAllStandardOutput(); //Reads standard output
                      QString StdError = proc->readAllStandardError(); // Reads standard error
                      ui->textEdit_Standard_output->setText(StdOut);
                      ui->textEdit_Standard_output->setText(StdError);
                      }

                      its building successfully, nothing printing on textedit can find some thing into this.
                      while debugging i saw slot function is not getting called.

                      jsulmJ 1 Reply Last reply
                      0
                      • M moyin

                        @jsulm

                        #include "transfer.h"
                        #include "ui_transfer.h"
                        #include <sstream>
                        #include <QProcess>
                        #include <iostream>
                        #include <QDebug>
                        #include <QFileDialog>
                        #include <QtWidgets>

                        Transfer::Transfer(QWidget *parent) :
                        QDialog(parent),
                        ui(new Ui::Transfer)
                        {
                        ui->setupUi(this);
                        }

                        Transfer::~Transfer()
                        {
                        delete ui;
                        }

                        void Transfer::on_pushButton_Go_clicked()
                        { proc = new QProcess() ;
                        QString command = "scp" ;
                        QString ip = ui->lineEdit_IP_Address->text() ;
                        QString username = ui->lineEdit_SSH_username->text() ;
                        QString dest_path = ui->lineEdit_TransferToTarget_DestinationFolder->text() ;
                        QString source_path = ui->lineEdit_TransferToTarget_SourcePath->text() ;
                        std::stringstream s ;
                        s << username.toStdString() << "@" << ip.toStdString() << ":" << dest_path.toStdString();
                        std::cout << s.str() << std::endl ;
                        QStringList params ;
                        params.append(source_path) ;
                        params.append(QString::fromStdString(s.str())) ;
                        qDebug() << params ;
                        // params.append("/home/span51/Desktop/readme.txt");
                        // params.append("spanidea@192.168.1.26:/home/spanidea/test" );
                        connect(this, SIGNAL(readyReadStandardError()), this, SLOT(readOutput()));
                        connect(this, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput()));
                        proc->startDetached(command,params) ;

                        /* QString StdOut = proc.readAllStandardOutput(); //Reads standard output
                        QString StdError = proc.readAllStandardError(); //Reads standard error
                        std::cout<<"\n Printing the standard output..........\n";
                        std::cout<<endl<<StdOut.toStdString();
                        std::cout<<"\n Printing the standard error..........\n";
                        std::cout<<endl<<StdError.toStdString();
                        */
                        }

                        void Transfer::on_pushButton_choosefile_transferTotarget_clicked()
                        {
                        QString filepath = QFileDialog::getOpenFileName(this, tr("Transfer file"), "/home","Config_Files(*.c)") ;
                        ui->lineEdit_TransferToTarget_SourcePath->setText(filepath);
                        }

                        void Transfer::on_pushButton_Std_output_clear_clicked()
                        {
                        ui->textEdit_Standard_output->clear() ;
                        }

                        void Transfer::on_checkBox_Show_Password_clicked(bool checked)
                        {
                        if (checked)
                        ui->lineEdit_SSH_password->setEchoMode(QLineEdit::Normal);
                        else
                        ui->lineEdit_SSH_password->setEchoMode(QLineEdit::Password);
                        }

                        void Transfer::readOutput()
                        {
                        QString StdOut = proc->readAllStandardOutput(); //Reads standard output
                        QString StdError = proc->readAllStandardError(); // Reads standard error
                        ui->textEdit_Standard_output->setText(StdOut);
                        ui->textEdit_Standard_output->setText(StdError);
                        }

                        its building successfully, nothing printing on textedit can find some thing into this.
                        while debugging i saw slot function is not getting called.

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @moyin said in How to Execute SCP command to transfer files to a target machine:

                        connect(this, SIGNAL(readyReadStandardError()), this, SLOT(readOutput()));
                        connect(this, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput()));

                        You should read more carefully. You need to connect the signals from the PROCESS not from this!

                        connect(process, SIGNAL(readyReadStandardError(), this, SLOT(readOutput()));
                        connect(process, SIGNAL(readyReadStandardOutput(), this, SLOT(readOutput()));
                        

                        You should also connect a slot to http://doc.qt.io/qt-5/qprocess.html#errorOccurred and print errors you get to be able to find issues faster.

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        M 1 Reply Last reply
                        1
                        • jsulmJ jsulm

                          @moyin said in How to Execute SCP command to transfer files to a target machine:

                          connect(this, SIGNAL(readyReadStandardError()), this, SLOT(readOutput()));
                          connect(this, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput()));

                          You should read more carefully. You need to connect the signals from the PROCESS not from this!

                          connect(process, SIGNAL(readyReadStandardError(), this, SLOT(readOutput()));
                          connect(process, SIGNAL(readyReadStandardOutput(), this, SLOT(readOutput()));
                          

                          You should also connect a slot to http://doc.qt.io/qt-5/qprocess.html#errorOccurred and print errors you get to be able to find issues faster.

                          M Offline
                          M Offline
                          moyin
                          wrote on last edited by
                          #12

                          @jsulm i tried this also,

                          connect(proc, SIGNAL(readyReadStandardError()), this, SLOT(readOutput()));
                          connect(proc, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput()));
                          proc->startDetached(command,params) ;

                          but same result, nothing will be printing on textedit.

                          jsulmJ 1 Reply Last reply
                          0
                          • M moyin

                            @jsulm i tried this also,

                            connect(proc, SIGNAL(readyReadStandardError()), this, SLOT(readOutput()));
                            connect(proc, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput()));
                            proc->startDetached(command,params) ;

                            but same result, nothing will be printing on textedit.

                            jsulmJ Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            @moyin Connect a slot to http://doc.qt.io/qt-5/qprocess.html#errorOccurred and see whether you get any error.

                            https://forum.qt.io/topic/113070/qt-code-of-conduct

                            M 1 Reply Last reply
                            2
                            • sierdzioS Offline
                              sierdzioS Offline
                              sierdzio
                              Moderators
                              wrote on last edited by
                              #14

                              @moyin said in How to Execute SCP command to transfer files to a target machine:

                              ui->textEdit_Standard_output->setText(StdOut);
                              ui->textEdit_Standard_output->setText(StdError);

                              If StdError is empty, then you are effectively overwriting your StdOut. Consider doing this instead:

                              ui->textEdit_Standard_output->setText(ui->textEdit_Standard_output->text() + StdOut + StdError);
                              

                              And please use code tags when writing on this forum, it makes reading the code much easier.

                              (Z(:^

                              1 Reply Last reply
                              3
                              • jsulmJ jsulm

                                @moyin Connect a slot to http://doc.qt.io/qt-5/qprocess.html#errorOccurred and see whether you get any error.

                                M Offline
                                M Offline
                                moyin
                                wrote on last edited by
                                #15

                                @jsulm i tried this, it does't works.

                                    connect(&proc, SIGNAL(readyReadStandardError()), this, SLOT(readOutput()));
                                    connect(&proc, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput()));
                                    connect(&proc, SIGNAL(errorOccurred()), this, SLOT(readOutput()));
                                    proc.startDetached(command,params) ;
                                

                                And did changes in readoutput() also,

                                    ui->textEdit_Standard_output->setText(ui->textEdit_Standard_output->toPlainText() + StdOut + StdError);
                                
                                
                                M jsulmJ 2 Replies Last reply
                                0
                                • M moyin

                                  @jsulm i tried this, it does't works.

                                      connect(&proc, SIGNAL(readyReadStandardError()), this, SLOT(readOutput()));
                                      connect(&proc, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput()));
                                      connect(&proc, SIGNAL(errorOccurred()), this, SLOT(readOutput()));
                                      proc.startDetached(command,params) ;
                                  

                                  And did changes in readoutput() also,

                                      ui->textEdit_Standard_output->setText(ui->textEdit_Standard_output->toPlainText() + StdOut + StdError);
                                  
                                  
                                  M Offline
                                  M Offline
                                  moyin
                                  wrote on last edited by
                                  #16

                                  @jsulm @sierdzio i'm sharing my .h and .cpp files as well it may help u to understand my problem.

                                  transfer.h

                                  #ifndef TRANSFER_H
                                  #define TRANSFER_H
                                  
                                  #include <QDialog>
                                  #include <QProcess>
                                  
                                  namespace Ui {
                                  class Transfer;
                                  }
                                  
                                  class Transfer : public QDialog
                                  {
                                      Q_OBJECT
                                  
                                  public:
                                      explicit Transfer(QWidget *parent = 0);
                                      ~Transfer();
                                  
                                  private slots:
                                      void on_pushButton_Go_clicked();
                                  
                                      void on_pushButton_choosefile_transferTotarget_clicked();
                                  
                                      void on_pushButton_Std_output_clear_clicked();
                                  
                                      void on_checkBox_Show_Password_clicked(bool checked);
                                  
                                      void readOutput() ;
                                  
                                  private:
                                      Ui::Transfer *ui;
                                      QProcess proc ;
                                  /*
                                  signals:
                                      void readyReadStandardOutput() ;
                                      void readyReadStandardError() ;
                                  */
                                  };
                                  
                                  #endif // TRANSFER_H
                                  
                                  

                                  transfer.cpp

                                  #include "transfer.h"
                                  #include "ui_transfer.h"
                                  #include <sstream>
                                  #include <QProcess>
                                  #include <iostream>
                                  #include <QDebug>
                                  #include <QFileDialog>
                                  #include <QtWidgets>
                                  
                                  
                                  Transfer::Transfer(QWidget *parent) :
                                      QDialog(parent),
                                      ui(new Ui::Transfer)
                                  {
                                      ui->setupUi(this);
                                  }
                                  
                                  Transfer::~Transfer()
                                  {
                                      delete ui;
                                  }
                                  
                                  
                                  void Transfer::on_pushButton_Go_clicked()
                                  {
                                      //proc = new QProcess() ;
                                      QString command = "scp" ;
                                      QString ip = ui->lineEdit_IP_Address->text() ;
                                      QString username = ui->lineEdit_SSH_username->text() ;
                                      QString dest_path = ui->lineEdit_TransferToTarget_DestinationFolder->text() ;
                                      QString source_path = ui->lineEdit_TransferToTarget_SourcePath->text() ;
                                      std::stringstream s ;
                                      s << username.toStdString() << "@" << ip.toStdString() << ":" << dest_path.toStdString();
                                      std::cout << s.str() << std::endl ;
                                      QStringList params ;
                                      params.append(source_path) ;
                                      params.append(QString::fromStdString(s.str())) ;
                                      qDebug() << params ;
                                      //    params.append("/home/span51/Desktop/readme.txt");
                                      //    params.append("spanidea@192.168.1.26:/home/spanidea/test" );
                                      connect(&proc, SIGNAL(readyReadStandardError()), this, SLOT(readOutput()));
                                      connect(&proc, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput()));
                                      connect(&proc, SIGNAL(errorOccurred()), this, SLOT(readOutput()));
                                      proc.startDetached(command,params) ;
                                  
                                  /*    QString StdOut      =   proc.readAllStandardOutput();  //Reads standard output
                                      QString StdError    =   proc.readAllStandardError();   //Reads standard error
                                      std::cout<<"\n Printing the standard output..........\n";
                                      std::cout<<endl<<StdOut.toStdString();
                                      std::cout<<"\n Printing the standard error..........\n";
                                      std::cout<<endl<<StdError.toStdString();
                                  */
                                  }
                                  
                                  void Transfer::on_pushButton_choosefile_transferTotarget_clicked()
                                  {
                                      QString filepath = QFileDialog::getOpenFileName(this, tr("Transfer file"), "/home","Config_Files(*.c)") ;
                                      ui->lineEdit_TransferToTarget_SourcePath->setText(filepath);
                                  }
                                  
                                  void Transfer::on_pushButton_Std_output_clear_clicked()
                                  {
                                      ui->textEdit_Standard_output->clear() ;
                                  }
                                  
                                  void Transfer::on_checkBox_Show_Password_clicked(bool checked)
                                  {
                                      if (checked)
                                          ui->lineEdit_SSH_password->setEchoMode(QLineEdit::Normal);
                                      else
                                          ui->lineEdit_SSH_password->setEchoMode(QLineEdit::Password);
                                  }
                                  
                                  void Transfer::readOutput()
                                  {
                                      QString StdOut = proc.readAllStandardOutput();  //Reads standard output
                                      QString StdError = proc.readAllStandardError(); // Reads standard error
                                  
                                  //    ui->textEdit_Standard_output->setText(StdOut);
                                  //    ui->textEdit_Standard_output->setText(StdError);
                                      ui->textEdit_Standard_output->setText(ui->textEdit_Standard_output->toPlainText() + StdOut + StdError);
                                  }
                                  
                                  
                                  1 Reply Last reply
                                  0
                                  • M moyin

                                    @jsulm i tried this, it does't works.

                                        connect(&proc, SIGNAL(readyReadStandardError()), this, SLOT(readOutput()));
                                        connect(&proc, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput()));
                                        connect(&proc, SIGNAL(errorOccurred()), this, SLOT(readOutput()));
                                        proc.startDetached(command,params) ;
                                    

                                    And did changes in readoutput() also,

                                        ui->textEdit_Standard_output->setText(ui->textEdit_Standard_output->toPlainText() + StdOut + StdError);
                                    
                                    
                                    jsulmJ Offline
                                    jsulmJ Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #17

                                    @moyin You again did not read documentation, right? http://doc.qt.io/qt-5/qprocess.html#errorOccurred
                                    Else you would see that errorOccurred() has a parameter.
                                    This connect cannot succeed (you should see a warning at runtime):

                                    connect(&proc, SIGNAL(errorOccurred()), this, SLOT(readOutput()));
                                    

                                    You need to use another slot with QProcess::ProcessError error parameter and print out its value.

                                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    M 1 Reply Last reply
                                    0
                                    • jsulmJ jsulm

                                      @moyin You again did not read documentation, right? http://doc.qt.io/qt-5/qprocess.html#errorOccurred
                                      Else you would see that errorOccurred() has a parameter.
                                      This connect cannot succeed (you should see a warning at runtime):

                                      connect(&proc, SIGNAL(errorOccurred()), this, SLOT(readOutput()));
                                      

                                      You need to use another slot with QProcess::ProcessError error parameter and print out its value.

                                      M Offline
                                      M Offline
                                      moyin
                                      wrote on last edited by
                                      #18

                                      @jsulm i can transfer file successfully to the target machine without errors. but wanted to redirect logs whatever (stdout,stderr, etc..,) to textedit. than
                                      why should go for QProcess::ProcessError.

                                      jsulmJ 1 Reply Last reply
                                      0
                                      • M moyin

                                        @jsulm i can transfer file successfully to the target machine without errors. but wanted to redirect logs whatever (stdout,stderr, etc..,) to textedit. than
                                        why should go for QProcess::ProcessError.

                                        jsulmJ Offline
                                        jsulmJ Offline
                                        jsulm
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #19

                                        @moyin Then check whether these connects actually were successful:

                                        qDebug() << connect(&proc, SIGNAL(readyReadStandardError()), this, SLOT(readOutput()));
                                        qDebug() << connect(&proc, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput()));
                                        

                                        Place a qDebug() in your readOutput() to print something out to see whether the slot is actually called.

                                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                                        M 2 Replies Last reply
                                        0
                                        • jsulmJ jsulm

                                          @moyin Then check whether these connects actually were successful:

                                          qDebug() << connect(&proc, SIGNAL(readyReadStandardError()), this, SLOT(readOutput()));
                                          qDebug() << connect(&proc, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput()));
                                          

                                          Place a qDebug() in your readOutput() to print something out to see whether the slot is actually called.

                                          M Offline
                                          M Offline
                                          moyin
                                          wrote on last edited by
                                          #20

                                          @jsulm i mentioned u already that, while debug if i put break point at or in readoutput() that will stop at break point so it means slot is not getting called.

                                          jsulmJ M 2 Replies 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