[PySide] Detecting which framework (PyQt or PySide) is active

Aaron Richiger a.richi at bluewin.ch
Mon Sep 3 18:16:09 CEST 2012


Hello David!

As far as I know, there is no direct function in the PySide (Qt) API to 
get the used technology. But others may know more... I could imagine two 
solutions:
- Dirty hack: Some things work in PySide, that do not work with PyQt4. 
You could try one of them and if it fails, then know that you are on PyQt4
- Get the info from the built-ins of the QApplication.instance() object, 
e.g. __repr__ . I wrote the following little script that checks what you 
asked for, but don't know whether it's usable for your purpose:


############ Code ####################
import sys

from PySide.QtCore import *
from PySide.QtGui import *

# from PyQt4.QtCore import *
# from PyQt4.QtGui import *

def is_PySide():
     return 'PySide' in repr(QApplication.instance())

def is_PyQt4():
     return 'PyQt4' in repr(QApplication.instance())


if __name__ == '__main__':
     app = QApplication(sys.argv)
     w = QWidget()
     w.show()
     print 'Is PySide:', is_PySide()
     print 'Is PyQt4: ', is_PyQt4()
     sys.exit(app.exec_())

###################################



Am 03.09.2012 17:47, schrieb David García Garzón:
> Hi, i am working on a CPython function i want to transparently run with either
> PyQt or PySide. It is a functions that builds an interface using C++ and then
> wraps it using either Sip (PyQt) or shiboken (PySide) in order to return it to
> python. The wrapping part was solved thanks to your help in a different thread
> but i still have the problem of knowing which wrapper i should use in a given
> situation.
>
> Is there some state (function, singletons, globals...) i could check? I am
> thinking on the pyside created QApp or any PySide state it requires to be
> initializated.
>
> Additional info: The library is split in two layers, a python and a C one, so
> it could be either api, but not in user code, so solution such as checking the
> imported modules are not convinient. If there is no api for that i am thinking
> in hacks like using PySide initializations required by QApp if any.
>
> Any ideas?
>
> David.
>
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside




More information about the PySide mailing list