return PyBool_FromLong((bool)%in); %out = %OUTTYPE(%in == Py_True); return PyLong_FromLong(%in); %out = %OUTTYPE(PyLong_AsLong(%in)); return PyLong_FromUnsignedLong(%in); %out = %OUTTYPE(PyLong_AsUnsignedLong(%in)); return PyLong_FromLong(%in); %out = %OUTTYPE(PyLong_AsLong(%in)); QByteArray ba = %in.toUtf8(); PyObject *%out = PyUnicode_FromStringAndSize(ba.constData(), ba.size()); return %out; #ifndef Py_LIMITED_API Py_UNICODE* unicode = PyUnicode_AS_UNICODE(%in); # if defined(Py_UNICODE_WIDE) // cast as Py_UNICODE can be a different type %out = QString::fromUcs4((const uint*)unicode); # else %out = QString::fromUtf16((const ushort*)unicode, PyUnicode_GET_SIZE(%in)); # endif #else wchar_t *temp = PyUnicode_AsWideCharString(%in, NULL); %out = QString::fromWCharArray(temp); PyMem_Free(temp); #endif #ifndef IS_PY3K const char* str = %CONVERTTOCPP[const char*](%in); %out = %OUTTYPE(str); #endif %out = %OUTTYPE(); const int N = %in.toString().length(); wchar_t *str = new wchar_t[N]; %in.toString().toWCharArray(str); PyObject *%out = PyUnicode_FromWideChar(str, N); delete[] str; return %out; wchar_t c = (wchar_t)%in.unicode(); return PyUnicode_FromWideChar(&c, 1); char c = %CONVERTTOCPP[char](%in); %out = %OUTTYPE(c); int i = %CONVERTTOCPP[int](%in); %out = %OUTTYPE(i); %out = %OUTTYPE(); if (!%in.isValid()) Py_RETURN_NONE; if (qstrcmp(%in.typeName(), "QVariantList") == 0) { QList<QVariant> var = %in.value<QVariantList>(); return %CONVERTTOPYTHON[QList<QVariant>](var); } if (qstrcmp(%in.typeName(), "QStringList") == 0) { QStringList var = %in.value<QStringList>(); return %CONVERTTOPYTHON[QList<QString>](var); } if (qstrcmp(%in.typeName(), "QVariantMap") == 0) { QMap<QString, QVariant> var = %in.value<QVariantMap>(); return %CONVERTTOPYTHON[QMap<QString, QVariant>](var); } Shiboken::Conversions::SpecificConverter converter(cppInRef.typeName()); if (converter) { void *ptr = cppInRef.data(); return converter.toPython(ptr); } PyErr_Format(PyExc_RuntimeError, "Can't find converter for '%s'.", %in.typeName()); return 0; %out = %OUTTYPE(%in == Py_True); %out = %OUTTYPE(); QString in = %CONVERTTOCPP[QString](%in); %out = %OUTTYPE(in); QByteArray in = %CONVERTTOCPP[QByteArray](%in); %out = %OUTTYPE(in); double in = %CONVERTTOCPP[double](%in); %out = %OUTTYPE(in); qlonglong in = %CONVERTTOCPP[qlonglong](%in); %out = %OUTTYPE(in); qlonglong in = %CONVERTTOCPP[qlonglong](%in); %out = %OUTTYPE(in); int in = %CONVERTTOCPP[int](%in); %out = %OUTTYPE(in); // a class supported by QVariant? int typeCode; const char *typeName = QVariant_resolveMetaType(Py_TYPE(%in), &typeCode); if (!typeCode || !typeName) return; QVariant var(typeCode, (void*)0); Shiboken::Conversions::SpecificConverter converter(typeName); converter.toCpp(pyIn, var.data()); %out = var; QVariant ret = QVariant_convertToVariantMap(%in); %out = ret.isValid() ? ret : QVariant::fromValue(PySide::PyObjectWrapper(%in)); QVariant ret = QVariant_convertToVariantList(%in); %out = ret.isValid() ? ret : QVariant::fromValue(PySide::PyObjectWrapper(%in)); // Is a shiboken type not known by Qt %out = QVariant::fromValue(PySide::PyObjectWrapper(%in)); const char *typeName = QVariant::typeToName(%in); PyObject *%out; PyTypeObject *pyType = nullptr; if (typeName) pyType = Shiboken::Conversions::getPythonTypeObject(typeName); %out = pyType ? (reinterpret_cast<PyObject*>(pyType)) : Py_None; Py_INCREF(%out); return %out; %out = QVariant::Invalid; const char *typeName; if (Shiboken::String::checkType(reinterpret_cast<PyTypeObject *>(%in))) typeName = "QString"; else if (%in == reinterpret_cast<PyObject*>(&PyFloat_Type)) typeName = "double"; // float is a UserType in QVariant. else if (%in == reinterpret_cast<PyObject*>(&PyLong_Type)) typeName = "int"; // long is a UserType in QVariant. else if (Py_TYPE(%in) == SbkObjectType_TypeF()) typeName = Shiboken::ObjectType::getOriginalName((SbkObjectType*)%in); else typeName = reinterpret_cast<PyTypeObject *>(%in)->tp_name; %out = QVariant::nameToType(typeName); %out = QVariant::nameToType(Shiboken::String::toCString(%in)); %out = QVariant::nameToType("QVariantMap"); %out = QVariantType_isStringList(%in) ? QVariant::StringList : QVariant::List; // The QVariantMap returned by QJsonObject seems to cause a segfault, so // using QJsonObject.toVariantMap() won't work. // Wrapping it in a QJsonValue first allows it to work QJsonValue val(%in); QVariant ret = val.toVariant(); return %CONVERTTOPYTHON[QVariant](ret); QVariant dict = QVariant_convertToVariantMap(%in); QJsonValue val = QJsonValue::fromVariant(dict); %out = val.toObject(); PyObject *%out = PyTuple_New(2); PyTuple_SET_ITEM(%out, 0, %CONVERTTOPYTHON[%INTYPE_0](%in.first)); PyTuple_SET_ITEM(%out, 1, %CONVERTTOPYTHON[%INTYPE_1](%in.second)); return %out; %out.first = %CONVERTTOCPP[%OUTTYPE_0](PySequence_Fast_GET_ITEM(%in, 0)); %out.second = %CONVERTTOCPP[%OUTTYPE_1](PySequence_Fast_GET_ITEM(%in, 1)); { // Avoid name clash Shiboken::AutoDecRef regFunc((PyObject*)NULL); Shiboken::AutoDecRef atexit(Shiboken::Module::import("atexit")); if (atexit.isNull()) { qWarning() << "Module atexit not found for registering __moduleShutdown"; PyErr_Clear(); }else{ regFunc.reset(PyObject_GetAttrString(atexit, "register")); if (regFunc.isNull()) { qWarning() << "Function atexit.register not found for registering __moduleShutdown"; PyErr_Clear(); } } if (!atexit.isNull() && !regFunc.isNull()){ PyObject *shutDownFunc = PyObject_GetAttrString(module, "__moduleShutdown"); Shiboken::AutoDecRef args(PyTuple_New(1)); PyTuple_SET_ITEM(args, 0, shutDownFunc); Shiboken::AutoDecRef retval(PyObject_Call(regFunc, args, 0)); Q_ASSERT(!retval.isNull()); } } Returns a read only buffer object pointing to the segment of data that this resource represents. If the resource is compressed the data returns is compressed and qUncompress() must be used to access the data. If the resource is a directory None is returned. %out = %OUTTYPE(); int day = PyDateTime_GET_DAY(%in); int month = PyDateTime_GET_MONTH(%in); int year = PyDateTime_GET_YEAR(%in); %out = %OUTTYPE(year, month, day); %out = %OUTTYPE(); int day = PyDateTime_GET_DAY(%in); int month = PyDateTime_GET_MONTH(%in); int year = PyDateTime_GET_YEAR(%in); int hour = PyDateTime_DATE_GET_HOUR(%in); int min = PyDateTime_DATE_GET_MINUTE(%in); int sec = PyDateTime_DATE_GET_SECOND(%in); int usec = PyDateTime_DATE_GET_MICROSECOND(%in); %out = %OUTTYPE(QDate(year, month, day), QTime(hour, min, sec, usec/1000)); %out = %OUTTYPE(); int hour = PyDateTime_TIME_GET_HOUR(%in); int min = PyDateTime_TIME_GET_MINUTE(%in); int sec = PyDateTime_TIME_GET_SECOND(%in); int usec = PyDateTime_TIME_GET_MICROSECOND(%in); %out = %OUTTYPE(hour, min, sec, usec/1000); To find the child of a certain QObject, the first argument of this function should be the child's type, and the second the name of the child: :: ... parent = QWidget() ... # The first argument must be the child type child1 = parent.findChild(QPushButton, "child_button") child2 = parent.findChild(QWidget, "child_widget") Like the method *findChild*, the first parameter should be the child's type. Replaces every occurrence of the regular expression in *sourceString* with *after*. Returns a new Python string with the modified contents. For example: :: s = "Banana" re = QRegExp("a[mn]") s = re.replace(s, "ox") # s == "Boxoxa" For regular expressions containing capturing parentheses, occurrences of \1, \2, ..., in *after* are replaced with rx.cap(1), cap(2), ... :: t = "A <i>bon mot</i>." re = QRegExp("<i>([^<]*)</i>") t = re.replace(t, "\\emph{\\1}") # t == "A \\emph{bon mot}." %out = %OUTTYPE(); #ifdef IS_PY3K %out = %OUTTYPE(PyBytes_AS_STRING(%in), PyBytes_GET_SIZE(%in)); #else %out = %OUTTYPE(Shiboken::String::toCString(%in), Shiboken::String::len(%in)); #endif %out = %OUTTYPE(PyByteArray_AsString(%in), PyByteArray_Size(%in)); %out = %OUTTYPE(Shiboken::String::toCString(%in), Shiboken::String::len(%in)); QByteArray ba(1 + int(%2), char(0)); %CPPSELF.%FUNCTION_NAME(ba.data(), int(%2)); %PYARG_0 = Shiboken::String::fromCString(ba.constData()); %RETURN_TYPE %out = 0; if (PyBytes_Check(%PYARG_0)) { %out = PyBytes_GET_SIZE((PyObject*)%PYARG_0); memcpy(%1, PyBytes_AS_STRING((PyObject*)%PYARG_0), %out); } else if (Shiboken::String::check(%PYARG_0)) { %out = Shiboken::String::len((PyObject*)%PYARG_0); memcpy(%1, Shiboken::String::toCString((PyObject*)%PYARG_0), %out); } QByteArray ba(1 + int(%2), char(0)); %CPPSELF.%FUNCTION_NAME(ba.data(), int(%2)); %PYARG_0 = Shiboken::String::fromCString(ba.constData()); %RETURN_TYPE %out = 0; if (PyBytes_Check(%PYARG_0)) { %out = PyBytes_GET_SIZE((PyObject*)%PYARG_0); memcpy(%1, PyBytes_AS_STRING((PyObject*)%PYARG_0), %out); } else if (Shiboken::String::check(%PYARG_0)) { %out = Shiboken::String::len((PyObject*)%PYARG_0); memcpy(%1, Shiboken::String::toCString((PyObject*)%PYARG_0), %out); } .. class:: QCoreApplication(args) Constructs a Qt kernel application. Kernel applications are applications without a graphical user interface. These type of applications are used at the console or as server processes. The *args* argument is processed by the application, and made available in a more convenient form by the :meth:`~QCoreApplication.arguments()` method. .. warning:: QSettings.value can return different types (QVariant types) depending on the platform it's running on, so the safest way to use it is always casting the result to the desired type, e.g.: int(settings.value("myKey")) QString &res = *%0; %PYARG_0 = %CONVERTTOPYTHON[QString](res); <code>machine = QStateMachine() s1 = QState() s11 = QState(s1) s12 = QState(s1) s1h = QHistoryState(s1) s1h.setDefaultState(s11) machine.addState(s1) s2 = QState() machine.addState(s2) button = QPushButton() # Clicking the button will cause the state machine to enter the child state # that s1 was in the last time s1 was exited, or the history state's default # state if s1 has never been entered. s1.addTransition(button.clicked, s1h)</code>