Important: Please read the Qt Code of Conduct -

Launched PySide2 app from Qt C++ is extremelly slow

  • Hi,

    After few days of struggling with binding Qt with PySide2 I finaly launched python module from Qt C++. Look at the picture below:

    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

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

  • @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;
        std::wstring pythonHome( L"C:/Anaconda3/envs/MyEnv38" );
        py::scoped_interpreter guard{}; // start the interpreter and keep it alive
        py::list path = py::module::import("sys").attr("path");
    //   py::eval_file("C:/"); // python module launcher via pybind
    /* standard python module launcher */
        PyObject *obj = Py_BuildValue("s", "C:/las_reader/");
        FILE *file = _Py_fopen_obj(obj, "r+");
        if(file != nullptr) {
            PyRun_SimpleFile(file, "C:/las_reader/");
        return 0;

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

Log in to reply