Click here to Skip to main content
15,890,717 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i have an question how can i get output from python by using QProcess.
there are one python script and QT project
i call python script from QProcess. it was done. but when i try to get output from my QProcess, i coudln`t get output. i got only Except Message from System.

my output is 'print' from python.

there are my sample code.
QT :
proc2 = new QProcess();
    proc2->setWorkingDirectory("My Directory");
    proc2->start("My Project");
    if(proc2->waitForStarted(-1)){
        while(proc2->waitForReadyRead(-1)){
            QByteArray a = proc2->readAllStandardOutput();
            qDebug()<<a;
        }
    }
    qDebug()<<"Finish";



and here is my python sample Project
import sys
import os
import time
def main():

    i = 0
    while True:
        print "test"
        sys.stout.flush()
        time.sleep(2)


when i run program, i coudln`t get "test" output.
but i checked if the program is runnung.

What I have tried:

connect ReadyRead Event in QT
i tried
print("")
sys.stout.write("")
print ""
at python.

when i run other my process by QProcess, i could get only Except Message.
but i coudln`t get output from 'print'
Posted
Updated 7-Jul-19 20:38pm

1 solution

Most likely because there is no such type as stout in sys. The correct type is stdout.
 
Share this answer
 
Comments
Member 14367686 8-Jul-19 2:45am    
i tried also sys.stdout but still can not read anything.
Member 14367686 8-Jul-19 2:56am    
oh. you was right. now i can get output from python. thank you so much

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900