Try to get qprocess output



  • Hi everyone!
    I have been working on running simple pyhton code when button is clicked. Here is the thing that I wanted to ask is;
    When I clicked the button, nothing happends. The pyton code is very simple it is just typing 'Hello!'. When I clicked the button, the terminal has to open or not? How can I get the 'Hello' output?

    
        connect(ui->deneme, &QPushButton::clicked,this, &MainWindow::startProcess);
    
    void MainWindow::startProcess(){
    
        QProcess process;
    
                process.setWorkingDirectory(QDir::currentPath());
                process.setProgram("python test.py");
                process.start("python test.py");
                process.waitForFinished(-1);
    }
    

    The following is the pyhton code;

    s='Hello!'
    print(s)
    

    Thanks for your help in advance!



  • @gizalp
    Why do you think python (or anything else) is going to open any terminal window? And what OS are you on anyway?

    For QProcess:setProgram you should have process.setProgram("python");, only. But in this case I think it's getting overridden by your process.start("python test.py"); so it doesn't matter, but it's wrong.

    If you want to grab a sub-process's output, you have to handle QProcess::readyReadStandardOutput(), and in there something like QByteArray QProcess::readAllStandardOutput(), if that's what you mean by "How can I get the 'Hello' output?".

    How this relates to Trying to implement thumbnail list I have no idea....


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.