PyQt vs PySide

前言

Python要調用C++ module可以透過SWIG, boost.python, SIP, Shiboken…etc.
又Qt是由C++編寫成的,所以PyQT以及PySide要連接QT當然是透過上面的Library來實現囉!
目前而言,PyQT選擇的是SIP,PySide選擇的是Shiboken。

如果不想搞太複雜,上述的基本觀念記住就好!

PyQT SIP

根據SIP官方的定義
https://riverbankcomputing.com/software/sip/intro

SIP is a tool that makes it very easy to create Python bindings for C and C++ libraries. It was originally developed to create PyQt, the Python bindings for the Qt toolkit, but can be used to create bindings for any C or C++ library.

簡單來說SIP一開始是為了PyQT綁定QT而被Riverbank Computing公司開發出來的工具,不過演變到現在SIP不限定再使用於PyQT,任何C or C++ library都可以透過SIP來讓Python使用。

PySide Shiboken

根據wiki.qt.io的解釋
https://wiki.qt.io/PySide_Shiboken

Shiboken is a plugin (front-end) for Generator Runner. It generates bindings for C++ libraries using CPython source code.

那Generator Runner又是什麼呢?
https://wiki.qt.io/PySide_Binding_Generator

The Generator Runner application is responsible for instantiating the API Extractor to parse the headers and binding information from the typesystem files, after that it will load and call the generator front-ends indicated by the user.

The Binding Generator Architecture is illustrated in the figure below.

Generator Runner是能夠讓開發者方便為C++和Qt擴展其他特定語言的工具。

Binding Generator Architecture.png

可以看的出來Generator Runner介於Api Extractor和front-end之間,Api Extractor先parse header files還有綁定typesystem files的資訊,然後透過Generator Runner綁定前端,來達成特定語言的擴展,這裡的前端就是Shiboken,特定語言就是Python(PySide)。

PyQt vs PySide

兩者使用的架構來說大致相同,更重要的差異在於授權。
PySide is LGPL while PyQt is GPL.
而LGPL授權允許二次開發後做閉源商業銷售,GPL授權若是要商業化,就需要將開發後的程式碼也做開源,並且繼承GPL協議。

參考

  1. Shiboken学习小结
    http://blog.csdn.net/dbzhang800/article/details/6386918

  2. PyQt or PySide - which one to use
    https://stackoverflow.com/a/6906509