Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Launched PySide2 app from Qt C++ is extremelly slow
Forum Updated to NodeBB v4.3 + New Features

Launched PySide2 app from Qt C++ is extremelly slow

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 477 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.
  • Please_Help_me_DP Offline
    Please_Help_me_DP Offline
    Please_Help_me_D
    wrote on last edited by
    #1

    Hi,

    After few days of struggling with binding Qt with PySide2 I finaly launched python module from Qt C++. Look at the picture below:
    27923fd2-e68d-45e1-ba14-95c7a4a73191-image.png

    There two instances of the same .py module: to the left is fast and launched from python, and to the right is extremely slow (almost unresponsible) launched from Qt/C++.

    When I launch it from Qt/C++ in application output I get the warning:

    • QObject::moveToThread: Current thread (0x275a700ce70) is not the object's thread (0x275a7032590).
    • Cannot move to target thread (0x275a700ce70)

    Please comment where maybe the reason of that...

    Release mode. PySide2 and Qt/C++ are both 5.14.2. I use MSVC 2017 x64 compiler and Python 3.8.5 x64, Windows 10 x64

    JonBJ 1 Reply Last reply
    0
    • Please_Help_me_DP Please_Help_me_D

      Hi,

      After few days of struggling with binding Qt with PySide2 I finaly launched python module from Qt C++. Look at the picture below:
      27923fd2-e68d-45e1-ba14-95c7a4a73191-image.png

      There two instances of the same .py module: to the left is fast and launched from python, and to the right is extremely slow (almost unresponsible) launched from Qt/C++.

      When I launch it from Qt/C++ in application output I get the warning:

      • QObject::moveToThread: Current thread (0x275a700ce70) is not the object's thread (0x275a7032590).
      • Cannot move to target thread (0x275a700ce70)

      Please comment where maybe the reason of that...

      Release mode. PySide2 and Qt/C++ are both 5.14.2. I use MSVC 2017 x64 compiler and Python 3.8.5 x64, Windows 10 x64

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #2

      @Please_Help_me_D
      Obviously the warnings are doubtless significant!
      How do you do this " launched python module from Qt C++"?

      Please_Help_me_DP 1 Reply Last reply
      0
      • JonBJ JonB

        @Please_Help_me_D
        Obviously the warnings are doubtless significant!
        How do you do this " launched python module from Qt C++"?

        Please_Help_me_DP Offline
        Please_Help_me_DP Offline
        Please_Help_me_D
        wrote on last edited by
        #3

        @JonB I've found the problem. It was QApplication wich used to be created in both Qt/C++ and in Python Module. After I commented QApplication in Qt/C++ it works normally. Now the problem is that PySide2 widget looks different if it is launched from Qt/C++.

        Here is the code maybe it will be useful for someone:

        #undef slots
            #include <pybind11/embed.h> // everything needed for embedding
            #include <pybind11/pybind11.h>
            namespace py = pybind11;
        #define slots
        
        #include <QApplication>
        
        int main(int argc, char *argv[])
        {
        //    QApplication a(argc, argv);
        //    MainWindow w;
        //    w.show();
        
            std::wstring pythonHome( L"C:/Anaconda3/envs/MyEnv38" );
            Py_SetPythonHome(pythonHome.c_str());
        
            py::scoped_interpreter guard{}; // start the interpreter and keep it alive
        
            py::list path = py::module::import("sys").attr("path");
            path.append("C:/las_reader");
        
        //   py::eval_file("C:/lasreader.py"); // python module launcher via pybind
        
        /* standard python module launcher */
            PyObject *obj = Py_BuildValue("s", "C:/las_reader/lasreader.py");
            FILE *file = _Py_fopen_obj(obj, "r+");
            if(file != nullptr) {
                PyRun_SimpleFile(file, "C:/las_reader/lasreader.py");
            }
        
            return 0;
        }
        
        1 Reply Last reply
        0
        • Please_Help_me_DP Offline
          Please_Help_me_DP Offline
          Please_Help_me_D
          wrote on last edited by
          #4

          The problem that Python called from Qt/C++ changes the style of application can be solved by copying the folder styles from C:\Anaconda3\envs\MyEnv38\Library\plugins to your built .exe file.

          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