-2

I'm using the QT Creator on Ubuntu. I have GUI with a mainwindow and another window called "progress". Upon clicking a button the QProcess starts and executes an rsync command which copies a folder into a specific directory. I created a textbrowser which reads the output from the rsync command. Also clicking the button causes the "progress" window to pop up. So far so so good, now my problem. Instead of showing the rsync output in my mainwindow i want it to be in progress. I've tried several methods to get the QProcess into the progress via connect but that doesn't seem to work.

mainwindow.cpp

void MainWindow::on_pushButton_clicked()
{

         if (ui->checkBox->isChecked()
           )
       m_time ="-t";


    QObject parent;
    m_myProcess =  new QProcess();
    connect(m_myProcess, SIGNAL(readyReadStandardOutput()),this, SLOT(printOutput()));

           QString program = "/usr/bin/rsync";

           arguments << "-r" << m_time << "-v" <<"--progress" <<"-s"

               << m_dir
               << m_dir2;




           m_myProcess->start(program, arguments);

          }

progress.cpp

void Progress::printOutput()
{


  ui->textBrowser->setPlainText(m_myProcess->readAllStandardOutput());
}

I know it's pretty messy iv'e tried alot of things and haven't cleaned the code yet also I'm pretty new to c++. My goal was to send the QProcess (m_myProcess) to progress via connect but that didn't seem to work. Can you send commands like readyReadAllStandardOutput via connect to other windows (I don't know the right term )? Am I doing a mistake or is there just another way to get the output to my progress window ?

Cœur
  • 37,241
  • 25
  • 195
  • 267
GemKnight
  • 3
  • 3
  • post a minimal example please. this is almost unreadable. [Check out this answer to a related question for QProcess->progressbar mechanisms](http://stackoverflow.com/questions/10166939/qprogressbar-hanging-at-98/10169668#10169668) – UmNyobe Aug 15 '14 at 08:49
  • Okay it should be readable now. Hopefully... Also thats's not my problem, but still usefull for the future thanks. – GemKnight Aug 15 '14 at 09:13
  • what is happening? nothing is being displayed? – UmNyobe Aug 15 '14 at 09:15
  • No , when i try to run it i get a error that m_myProcess was not declared in the progress.cpp scope. "m_myProcess' was not declared in this scope" – GemKnight Aug 15 '14 at 09:18
  • this is a compilation error *facepalm*. – UmNyobe Aug 15 '14 at 09:38

1 Answers1

0

m_myProcess is a member of the class MainWindow and you haven't made it visible to the class Progress. That's why you have the compilation error

m_myProcess was not declared in this scope

What you could do:

  1. Redirect standard error of m_myProcess to standard output, such that you also print what is sent to standard error (unless you want to do something else with it). Using

    m_myProcess.setProcessChannelMode(QProcess::MergedChannels);  
    
  2. Make the process object available outside MainWindow

    QProcess* MainWindow::getProcess()
    {
       return  m_myProcess;
    }
    
  3. Read the process output line by line in Progress. It needs to be saved in a buffer because readAllStandardOutput() only return the data which has been written since the last read.

    ... // somewhere
    connect(window->getProcess(), SIGNAL(readyReadStandardOutput()), this, SLOT(printOutput())
    ...
    
    void Progress::printOutput(){
       //bigbuffer is member
       bigbuffer.append(myProcess->readAllStandardOutput();)
       ui->textBrowser->setPlainText(bigbuffer);
    }
    
UmNyobe
  • 22,539
  • 9
  • 61
  • 90