Wrap the given pointer with shiboken and return the appropriate QObject

    :returns: if ptr is not None returns a QObject that is cast to the appropriate class
    :rtype: QObject | None
    :raises: None

def wrap(ptr, base=None):
    """Wrap the given pointer with shiboken and return the appropriate QObject

    :returns: if ptr is not None returns a QObject that is cast to the appropriate class
    :rtype: QObject | None
    :raises: None
    """
    if ptr is None:
        return None
    ptr = long(ptr) # Ensure type
    if base is None:
        qObj = shiboken.wrapInstance(long(ptr), QtCore.QObject)
        metaObj = qObj.metaObject()
        cls = metaObj.className()
        superCls = metaObj.superClass().className()
        if hasattr(QtGui, cls):
            base = getattr(QtGui, cls)
        elif hasattr(QtGui, superCls):
            base = getattr(QtGui, superCls)
        else:
            base = QtGui.QWidget
    return shiboken.wrapInstance(long(ptr), base)