QProcess with pythonQt
-
Hi,
I am trying to show the output of a python script that I am running in my c++ application using pythonQt and show it on QTextBrowser. I was looking into QProcess but I'm unable to run it at present. My actual code looks like this without QProcess:PythonQt::init(); PythonQtObjectPtr context = PythonQt::self()->getMainModule(); context.addVariable("puid", variable); context.evalScript(QString("import os,sys\n" "from somelib import this\n" "this.load(puid)"));
Now I'm trying to wrap it with QProcess and using QProcess's signal SIGNAL(readyRead()), trying to read and append output to QTextBrowser. This is the code I'm trying to wrap
PythonQt::init(); PythonQtObjectPtr context = PythonQt::self()->getMainModule(); context.addVariable("puid",variable); QString command = QString("import os,sys\n" "from lib import this\n" "this.load(puid)"); QString e = "context.evalScript(command)"; process->start(e); //process is instance of QProcess here
This works when I use any one single line command but when I do something like above it does not work and I think I'm doing it wrong so just want to know is it possible to do something like this, to append output of this command to QTextBrowser using QProcess. In short, I want to run context.evalScript command using QProcess and read the output and show on QTextBrowser. Thanks
-
Hi,
I am trying to show the output of a python script that I am running in my c++ application using pythonQt and show it on QTextBrowser. I was looking into QProcess but I'm unable to run it at present. My actual code looks like this without QProcess:PythonQt::init(); PythonQtObjectPtr context = PythonQt::self()->getMainModule(); context.addVariable("puid", variable); context.evalScript(QString("import os,sys\n" "from somelib import this\n" "this.load(puid)"));
Now I'm trying to wrap it with QProcess and using QProcess's signal SIGNAL(readyRead()), trying to read and append output to QTextBrowser. This is the code I'm trying to wrap
PythonQt::init(); PythonQtObjectPtr context = PythonQt::self()->getMainModule(); context.addVariable("puid",variable); QString command = QString("import os,sys\n" "from lib import this\n" "this.load(puid)"); QString e = "context.evalScript(command)"; process->start(e); //process is instance of QProcess here
This works when I use any one single line command but when I do something like above it does not work and I think I'm doing it wrong so just want to know is it possible to do something like this, to append output of this command to QTextBrowser using QProcess. In short, I want to run context.evalScript command using QProcess and read the output and show on QTextBrowser. Thanks
@sogo said in QProcess with pythonQt:
context.evalScript(command)
I fail to understand how this should work?
This is neither an executable nor a script, so how can it be executed as a process?
QProcess starts a process to execute an executable or script. -
-
Hi @jsulm,
What I thought and correct me if I'm wrong is that context.evalScript("some python script") is a command which executes process for running python scripts and QProcess can start this. It is just like another command that executes something.@sogo said in QProcess with pythonQt:
and QProcess can start this
How?
Just try to enter "context.evalScript(command)" in a terminal and see what happens. As I said QProcess starts binaries and scripts in a new process. -
I think now I understand what you mean. Would it need < from line "pythonQt::init"> to <last line of eval.Script> as one script and "variable" as argument to pass to that script. Would that work.
Edit: Sorry, It will not work. Is there any way I can get the terminal output to show on text browser for when it executes this context.evalScript? -
Hi,
Based on a quick look at the official example, you need to use the call method to actually do something and get a result back.
-
Hi,
Based on a quick look at the official example, you need to use the call method to actually do something and get a result back.