Important: Please read the Qt Code of Conduct -

show other program result in QWindow

  • hi,
    As we know project in Qt can be written in C++.but if want after clicking a push button can it possible to get output from python program and show on QLabel .
    Actually i want to get resultant output from python code after clicking a button while our Qt project is in C++.
    for example if i am doing image differencing (program written in python )then output of two image difference should be appear on Qt gui

  • Lifetime Qt Champion

    Hi and welcome to the forums
    You can use QProcess to run python scripts

    But if you need to show the difference between 2 images, i think you will have to let the python
    save that to a file and then read in the c++ part.

  • if we are taking path of image through FileDialog in Qt C++ gui ,then how can we get that image path to python program..

  • Lifetime Qt Champion

    With QProcess you can include arguments the the python app can read.

  • @jsulm @mrjj @SGaist
    i have tried to run execute python program on button click but getting error ......
    Qt program:---

    QProcess p;
    QStringList params;
    qDebug()<<"Pythonerror:"<<p_stderr; programm)

    from PIL import Image
    import numpy as np
    def change(path1,path2):,"r"),"r")


    ERROR on QT:
    Python error: "Traceback (most recent call last):\r\n File "C:/Users/user/Desktop/image/", line 1, in <module>\r\n from PIL import Image\r\n File "C:\Users\user\anaconda3\lib\site-packages\PIL\", 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:
    #python program is same as

    Error (Qt):
    File "C:/Users/user/Desktop/image/", line 1, in <module>
    from PIL import Image
    File "C:\Users\user\anaconda3\lib\site-packages\PIL\", line 94, in <module>
    from . import _imaging as core
    ImportError: DLL load failed while importing _imaging: The specified module could not be found.

  • Lifetime Qt Champion

    @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.

  • @jsulm
    yes my python code is running proprly .Even when i replace another program(i.e gave output without error on Qt itself.
    & when executing on spider(anaconda) shows the output and save in specified location.

  • @daisyvish
    If you edit your post to include the code tags, like @jsulm said, I will have a look at it.....

  • Lifetime Qt Champion


    How are you calling your python script on the command line ?
    Do you have any environment variable set that is different in Qt Creator ?

  • @mrjj @jsulm @SGaist
    I have posted the program please once check that if any correction reqiured .I used anaconda IDE (spyder) for python.

  • @SGaist i am trying to call python program from QT to check environment variables for QT?

  • Lifetime Qt Champion

    @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

Log in to reply