Using Custom Qt Subclasses in Python

First: I am new to Qt and SWIG. Currently reading the documentation for both of them, but this is a time consuming task, so I'm looking for some spoilers. It’s good to know if something will just work.

I am trying to formulate a modular architecture for some of my own programs. The main components are in C ++ and are available through SWIG for Python for experimenting and rapid prototyping of new components. Qt seems like it has some classes that I could use to avoid reinventing the wheel too much, but I'm concerned about how some of the bits will fit together.

In particular, if I create some C ++ classes, I will need to open them through SWIG. Some of these classes are likely to be subclasses of Qt classes or otherwise have Qt material exposed in their public interfaces. It seems that this may cause some complications.

There are already two interfaces for Qt in Python, PyQt and PySide. Probably will use PySide for licensing reasons. About how painful I should expect to get a SWIG-wrapped custom subclass of Qt to play well with any of them? What complications should I know in advance?

+3
source share
1 answer

PyQt provides C ++ code for Python through SIP ; PySide does this through Shiboken . Both have roughly the same capabilities as SWIG (except that they only support advanced C ++ to Python), while SWIG has a back-end for Ruby, Perl, Java, etc.). Neither SWIG, nor SIP, and Shiboken are designed to communicate with each other. You could not conveniently use SWIG to wrap any code with the C ++ extensions that Qt requires (to support signals and slots), and I have no idea that danger cannot wait for you in an attempt to interact SIP-packed (or Shiboken wrapped ) and SWIG-trimmed code.

Why, may I ask, did you decide to use two separate and equivalent methods of wrapping the different parts of your C ++ code base (Qt via SIP or Shiboken, everything else through SWIG)? If you can still rethink this odd design decision, I highly recommend you do it.

If your SWIG choice is carved out of stone, I predict big problems every time I complete C ++ code using Qt extensions (i.e. slots or signals) and, as a rule, a very miserable time for all participants. If you choose one way to wrap and stick to it, the problems should be greatly reduced. I have no real experience with Shiboken (this is a bit new, and I almost never make GUI applications these days anymore ... my world is all a web application!), But I used SIP in this role in the past (return path before it was decently documented - these days it seems to me that it’s beautifully documented, and a superficial reading of Shiboken gives me the same impression), and I can recommend it highly (actually, if I could choose this would be an option, probably preferable for SWIG, even if not involved in the project l Qt-code).

+7
source

Source: https://habr.com/ru/post/1200665/


All Articles