show other program result in QWindow
-
if we are taking path of image through FileDialog in Qt C++ gui ,then how can we get that image path to python program..
@daisyvish
With QProcess you can include arguments the the python app can read.
https://stackoverflow.com/questions/47276571/qprocess-passing-arguments-to-a-python-script -
@jsulm @mrjj @SGaist
i have tried to run execute python program on button click but getting error ......
Qt program:---QProcess p;
QStringList params;
params<<"C:/Users/user/Desktop/image/temp.py";
p.start("C:/Users/user/anaconda3/python.exe",params);
p.waitForFinished(-1);
qDebug()<<"finished";
QStringp_stdout=p.readAll();
qDebug()<<p_stdout;
QStringp_stderr=p.readAllStandardError();
if(!p_stderr.isEmpty());
qDebug()<<"Pythonerror:"<<p_stderr;
temp.py:---(python programm)from PIL import Image
import numpy as np
def change(path1,path2):
im1=Image.open(path1,"r")
im2=Image.open(path2,"r")
buffer1=np.asarray(im1)
buffer2=np.asarray(im2)
buffer3=buffer1-buffer2
changed=Image.fromarray(buffer3)
im1.show()
im2.show()
changed.show()
changed.save(r"C:\Users\user\Desktop\image\changed.jpg")
return(changed.show)change(r"C:\Users\user\Desktop\image\Vale.jpg",r"C:\Users\user\Desktop\image\Vale2.jpg")
ERROR on QT:
finished
""
Python error: "Traceback (most recent call last):\r\n File "C:/Users/user/Desktop/image/temp.py", line 1, in <module>\r\n from PIL import Image\r\n File "C:\Users\user\anaconda3\lib\site-packages\PIL\Image.py", line 94, in <module>\r\n from . import _imaging as core\r\nImportError: DLL load failed while importing _imaging: The specified module could not be found.\r\n"Second approach in Qt:
QStringprogram("C:/Users/user/anaconda3/python.exe");
QStringListargs=QStringList()<<"C:/Users/user/Desktop/image/temp.py";
intexitcode=QProcess::execute(program,args);
#python program is same as temp.pyError (Qt):
File "C:/Users/user/Desktop/image/temp.py", line 1, in <module>
from PIL import Image
File "C:\Users\user\anaconda3\lib\site-packages\PIL\Image.py", line 94, in <module>
from . import _imaging as core
ImportError: DLL load failed while importing _imaging: The specified module could not be found. -
@jsulm @mrjj @SGaist
i have tried to run execute python program on button click but getting error ......
Qt program:---QProcess p;
QStringList params;
params<<"C:/Users/user/Desktop/image/temp.py";
p.start("C:/Users/user/anaconda3/python.exe",params);
p.waitForFinished(-1);
qDebug()<<"finished";
QStringp_stdout=p.readAll();
qDebug()<<p_stdout;
QStringp_stderr=p.readAllStandardError();
if(!p_stderr.isEmpty());
qDebug()<<"Pythonerror:"<<p_stderr;
temp.py:---(python programm)from PIL import Image
import numpy as np
def change(path1,path2):
im1=Image.open(path1,"r")
im2=Image.open(path2,"r")
buffer1=np.asarray(im1)
buffer2=np.asarray(im2)
buffer3=buffer1-buffer2
changed=Image.fromarray(buffer3)
im1.show()
im2.show()
changed.show()
changed.save(r"C:\Users\user\Desktop\image\changed.jpg")
return(changed.show)change(r"C:\Users\user\Desktop\image\Vale.jpg",r"C:\Users\user\Desktop\image\Vale2.jpg")
ERROR on QT:
finished
""
Python error: "Traceback (most recent call last):\r\n File "C:/Users/user/Desktop/image/temp.py", line 1, in <module>\r\n from PIL import Image\r\n File "C:\Users\user\anaconda3\lib\site-packages\PIL\Image.py", line 94, in <module>\r\n from . import _imaging as core\r\nImportError: DLL load failed while importing _imaging: The specified module could not be found.\r\n"Second approach in Qt:
QStringprogram("C:/Users/user/anaconda3/python.exe");
QStringListargs=QStringList()<<"C:/Users/user/Desktop/image/temp.py";
intexitcode=QProcess::execute(program,args);
#python program is same as temp.pyError (Qt):
File "C:/Users/user/Desktop/image/temp.py", line 1, in <module>
from PIL import Image
File "C:\Users\user\anaconda3\lib\site-packages\PIL\Image.py", line 94, in <module>
from . import _imaging as core
ImportError: DLL load failed while importing _imaging: The specified module could not be found.@daisyvish Does your script work if you run it manually?
From what you posted the Python interpreter cannot find some modules.And please try to format your code properly to make it easier to read.
-
-
-
Hi,
How are you calling your python script on the command line ?
Do you have any environment variable set that is different in Qt Creator ? -
Hi,
How are you calling your python script on the command line ?
Do you have any environment variable set that is different in Qt Creator ? -
@SGaist i am trying to call python program from QT button..how to check environment variables for QT?
@daisyvish said in show other program result in QWindow:
how to check environment variables for QT?
You mean in "in QtCreator"? @SGaist did not ask about environment variables specific for Qt, but any variables which can influence Python.
Go to "Projects/YOUR_KIT/Run/Run Environment" and compare the environment variables there to what "set" outputs in cmd.exe -
if you do this work,please also shared with me. I also need this