Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved Launched PySide2 app from Qt C++ is extremelly slow

    General and Desktop
    2
    4
    208
    Loading More Posts
    • 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_D
      Please_Help_me_D last edited by

      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

      JonB 1 Reply Last reply Reply Quote 0
      • JonB
        JonB @Please_Help_me_D last edited by

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

        Please_Help_me_D 1 Reply Last reply Reply Quote 0
        • Please_Help_me_D
          Please_Help_me_D @JonB last edited by

          @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 Reply Quote 0
          • Please_Help_me_D
            Please_Help_me_D last edited by

            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 Reply Quote 0
            • First post
              Last post