Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. show other program result in QWindow
QtWS25 Last Chance

show other program result in QWindow

Scheduled Pinned Locked Moved Unsolved Qt for Python
pyside2qt for python
13 Posts 6 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mrjj
    Lifetime Qt Champion
    wrote on 25 Sept 2020, 05:28 last edited by
    #2

    Hi and welcome to the forums
    You can use QProcess to run python scripts
    https://stackoverflow.com/questions/19185056/qprocess-not-executing-a-python-script

    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.

    1 Reply Last reply
    4
    • D Offline
      D Offline
      daisyvish
      wrote on 29 Sept 2020, 04:28 last edited by
      #3

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

      M 1 Reply Last reply 29 Sept 2020, 04:59
      0
      • D daisyvish
        29 Sept 2020, 04:28

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

        M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 29 Sept 2020, 04:59 last edited by
        #4

        @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

        1 Reply Last reply
        4
        • D Offline
          D Offline
          daisyvish
          wrote on 9 Oct 2020, 11:13 last edited by daisyvish 10 Dec 2020, 06:00
          #5

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

          Error (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.

          J 1 Reply Last reply 9 Oct 2020, 11:18
          0
          • D daisyvish
            9 Oct 2020, 11:13

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

            Error (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.

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 9 Oct 2020, 11:18 last edited by
            #6

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

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • D Offline
              D Offline
              daisyvish
              wrote on 9 Oct 2020, 11:25 last edited by daisyvish 10 Sept 2020, 11:54
              #7

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

              JonBJ 1 Reply Last reply 9 Oct 2020, 11:41
              0
              • D daisyvish
                9 Oct 2020, 11:25

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

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on 9 Oct 2020, 11:41 last edited by
                #8

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

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 9 Oct 2020, 18:54 last edited by
                  #9

                  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 ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  D 1 Reply Last reply 21 Oct 2020, 05:17
                  0
                  • D Offline
                    D Offline
                    daisyvish
                    wrote on 12 Oct 2020, 06:05 last edited by
                    #10

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

                    1 Reply Last reply
                    0
                    • SGaistS SGaist
                      9 Oct 2020, 18:54

                      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 ?

                      D Offline
                      D Offline
                      daisyvish
                      wrote on 21 Oct 2020, 05:17 last edited by
                      #11

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

                      J 1 Reply Last reply 21 Oct 2020, 05:22
                      0
                      • D daisyvish
                        21 Oct 2020, 05:17

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

                        J Offline
                        J Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on 21 Oct 2020, 05:22 last edited by
                        #12

                        @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

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          Muqadas noor
                          wrote on 20 Sept 2022, 13:47 last edited by
                          #13

                          if you do this work,please also shared with me. I also need this

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved