How to bind qt to python? (boost.python).
Solved
Language Bindings
-
Hello!
I bind my library (it usesQThread
andQSslSocket
) to Python.
I use qt/5.15.3 and boost/1.77.0.My wrapper:
class AuthThreadWrapper : public AuthThread // AuthThread inherits by QThread { Q_OBJECT public: AuthThreadWrapper(QObject *parent, const std::string ip, Ed25519Certificate& cert, Credentials &credentials) : AuthThread(parent, QString::fromStdString(ip), cert, credentials) { QObject::connect(this, &AuthThread::error, this, &AuthThreadWrapper::onError); QObject::connect(this, &AuthThread::connected, this, &AuthThreadWrapper::onConnected); QObject::connect(this, &AuthThread::disconnected, this, &AuthThreadWrapper::onDisconnected); QObject::connect(this, &AuthThread::loggedOut, this, &AuthThreadWrapper::onLogout); QObject::connect(this, &AuthThread::stopped, this, &AuthThreadWrapper::onStopped); QObject::connect(this, &AuthThread::listUsersInfoUpdated, this, &AuthThreadWrapper::onListUsersInfoUpdated); } ~AuthThreadWrapper() {} int exec() { return QThread::exec(); } void onConnectedHandler(boost::python::object callback) { _onConnectedCallback = callback; } void onDisconnectedHandler(boost::python::object callback) { _onDisconnectedCallback = callback; } void onLogoutHandler(boost::python::object callback) { _onLogoutCallback = callback; } void onStoppedHandler(boost::python::object callback) { _onStoppedCallback = callback; } void onErrorHandler(boost::python::object callback) { _onErrorCallback = callback; } void onListUsersInfoUpdatedHandler(boost::python::object callback) { _onListUsersInfoUpdatedCallback = callback; } private: boost::python::object _onConnectedCallback; boost::python::object _onDisconnectedCallback; boost::python::object _onLogoutCallback; boost::python::object _onStoppedCallback; boost::python::object _onErrorCallback; boost::python::object _onListUsersInfoUpdatedCallback; public Q_SLOTS: void onStopped() { if(_onStoppedCallback) { _onStoppedCallback(); } } void onConnected(bool value) { if(_onConnectedCallback) { _onConnectedCallback(value); } } void onDisconnected() { if(_onDisconnectedCallback) { _onDisconnectedCallback(); } } void onLogout() { if(_onLogoutCallback) { _onLogoutCallback(); } } void onError(const QString msg, const Auth::ErrorType errType) { if (_onErrorCallback) { _onErrorCallback(msg, errType); } } void onListUsersInfoUpdated(const QString msg) { if (_onListUsersInfoUpdatedCallback) { _onListUsersInfoUpdatedCallback(msg); } } };
import auth_client_python_api from PySide2 import * ///... if __name__ == '__main__': t = auth_client_python_api.AuthThreadWrapper(None, ip, cert, creds) t.on_stopped(stop_handler) t.on_connected(connect_handler) t.on_error(err_handler) app = QApplication(sys.argv) t.connect(); t.start(); sys.exit(app.exec_())
It does not work with
PySide2
.QSslSocket
does not emit the signalQAbstractSocket::readyRead
.
If when I do not use QApplication, the program writes "QEventLoop: Cannot be used without QApplication".
How to do without QApplication?
Please help me. -
@mhanusek said in How to bind qt to python? (boost.python).:
If when I do not use QApplication, the program writes "QEventLoop: Cannot be used without QApplication".
How to do without QApplication?I don't follow: you cannot have a
QEventLoop
without aQApplication
(or one of its base classes), hence the error message. So answer to "How to do without QApplication?" is you cannot. -