import sip
API_NAMES = ["QDate", "QDateTime", "QString", "QTextStream", "QTime", "QUrl", "QVariant"]
API_VERSION = 2
for name in API_NAMES:
sip.setapi(name, API_VERSION)
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtSvg import *
from PyQt4.QtCore import pyqtSignal as Signal
from PyQt4.QtCore import pyqtSlot as Slot
PyQt provides limited support for multiple incompatible APIs and the ability for an application to select between them at run-time. For example, an application can choose whether QString is implemented as a Python type, or is automatically converted to and from a Python v2 unicode object or a Python v3 string object.
This ability allows developers to decide how to manage the transition from an older deprecated, API to a newer incompatible API.
Each API that can be selected in this way has a name and a range of version numbers. An application calls sip.setapi() to set the version number of a particular API. This call must be made before any module that implements the API is imported. Once set the version number cannot be changed. If not set then an API will use its default version.
For example the following code will disable the use of QString:
import sip
sip.setapi('QString', 2)
from PyQt4 import QtCore
# This will raise an attribute exception because QString is only wrapped
# in version 1 of the API.
s = QtCore.QString()
从this reddit comment
(…虽然我建议使用
from PyQt4 import QtCore
等代替import *
)也许您可以尝试使用^{} 。文档中的一个简单示例:
以及支持的API列表:
^{pr2}$看看Riverbank的“不兼容api”site
相关问题 更多 >
编程相关推荐