/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt for Python.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

//workaround to access protected functions
#define protected public

// default includes
#include <shiboken.h>
#ifndef QT_NO_VERSION_TAGGING
#  define QT_NO_VERSION_TAGGING
#endif
#include <QDebug>
#include <pysidesignal.h>
#include <pysideproperty.h>
#include <pyside.h>
#include <pysideqenum.h>
#include <feature_select.h>
QT_WARNING_DISABLE_DEPRECATED

#include <typeinfo>
#include <signalmanager.h>
#include <pysidemetafunction.h>
#include <iterator>

// module include
#include "pyside6_qtcore_python.h"

// main header
#include "qthreadpool_wrapper.h"

// inner classes

#include <cctype>
#include <cstring>



template <class T>
static const char *typeNameOf(const T &t)
{
    const char *typeName =  typeid(t).name();
    auto size = std::strlen(typeName);
#if defined(Q_CC_MSVC) // MSVC: "class QPaintDevice * __ptr64"
    if (auto lastStar = strchr(typeName, '*')) {
        // MSVC: "class QPaintDevice * __ptr64"
        while (*--lastStar == ' ') {
        }
        size = lastStar - typeName + 1;
    }
#else // g++, Clang: "QPaintDevice *" -> "P12QPaintDevice"
    if (size > 2 && typeName[0] == 'P' && std::isdigit(typeName[1])) {
        ++typeName;
        --size;
    }
#endif
    char *result = new char[size + 1];
    result[size] = '\0';
    memcpy(result, typeName, size);
    return result;
}

// Native ---------------------------------------------------------

void QThreadPoolWrapper::resetPyMethodCache()
{
    std::fill_n(m_PyMethodCache, sizeof(m_PyMethodCache) / sizeof(m_PyMethodCache[0]), false);
}

QThreadPoolWrapper::QThreadPoolWrapper(QObject * parent) : QThreadPool(parent)
{
    resetPyMethodCache();
    // ... middle
}

void QThreadPoolWrapper::childEvent(QChildEvent * event)
{
    if (m_PyMethodCache[0]) {
        return this->::QObject::childEvent(event);
    }
    Shiboken::GilState gil;
    if (PyErr_Occurred())
        return;
    static PyObject *nameCache[2] = {};
    static const char *funcName = "childEvent";
    Shiboken::AutoDecRef pyOverride(Shiboken::BindingManager::instance().getOverride(this, nameCache, funcName));
    if (pyOverride.isNull()) {
        gil.release();
        m_PyMethodCache[0] = true;
        return this->::QObject::childEvent(event);
    }

    Shiboken::AutoDecRef pyArgs(Py_BuildValue("(N)",
        Shiboken::Conversions::pointerToPython(SbkPySide6_QtCoreTypes[SBK_QCHILDEVENT_IDX], event)
    ));
    bool invalidateArg1 = PyTuple_GET_ITEM(pyArgs, 0)->ob_refcnt == 1;

    Shiboken::AutoDecRef pyResult(PyObject_Call(pyOverride, pyArgs, nullptr));
    if (invalidateArg1)
        Shiboken::Object::invalidate(PyTuple_GET_ITEM(pyArgs, 0));
    if (pyResult.isNull()) {
        // An error happened in python code!
        PyErr_Print();
        return;
    }
}

void QThreadPoolWrapper::connectNotify(const QMetaMethod & signal)
{
    if (m_PyMethodCache[1]) {
        return this->::QObject::connectNotify(signal);
    }
    Shiboken::GilState gil;
    if (PyErr_Occurred())
        return;
    static PyObject *nameCache[2] = {};
    static const char *funcName = "connectNotify";
    Shiboken::AutoDecRef pyOverride(Shiboken::BindingManager::instance().getOverride(this, nameCache, funcName));
    if (pyOverride.isNull()) {
        gil.release();
        m_PyMethodCache[1] = true;
        return this->::QObject::connectNotify(signal);
    }

    Shiboken::AutoDecRef pyArgs(Py_BuildValue("(N)",
        Shiboken::Conversions::copyToPython(SbkPySide6_QtCoreTypes[SBK_QMETAMETHOD_IDX], &signal)
    ));

    Shiboken::AutoDecRef pyResult(PyObject_Call(pyOverride, pyArgs, nullptr));
    if (pyResult.isNull()) {
        // An error happened in python code!
        PyErr_Print();
        return;
    }
}

void QThreadPoolWrapper::customEvent(QEvent * event)
{
    if (m_PyMethodCache[2]) {
        return this->::QObject::customEvent(event);
    }
    Shiboken::GilState gil;
    if (PyErr_Occurred())
        return;
    static PyObject *nameCache[2] = {};
    static const char *funcName = "customEvent";
    Shiboken::AutoDecRef pyOverride(Shiboken::BindingManager::instance().getOverride(this, nameCache, funcName));
    if (pyOverride.isNull()) {
        gil.release();
        m_PyMethodCache[2] = true;
        return this->::QObject::customEvent(event);
    }

    Shiboken::AutoDecRef pyArgs(Py_BuildValue("(N)",
        Shiboken::Conversions::pointerToPython(SbkPySide6_QtCoreTypes[SBK_QEVENT_IDX], event)
    ));
    bool invalidateArg1 = PyTuple_GET_ITEM(pyArgs, 0)->ob_refcnt == 1;

    Shiboken::AutoDecRef pyResult(PyObject_Call(pyOverride, pyArgs, nullptr));
    if (invalidateArg1)
        Shiboken::Object::invalidate(PyTuple_GET_ITEM(pyArgs, 0));
    if (pyResult.isNull()) {
        // An error happened in python code!
        PyErr_Print();
        return;
    }
}

void QThreadPoolWrapper::disconnectNotify(const QMetaMethod & signal)
{
    if (m_PyMethodCache[3]) {
        return this->::QObject::disconnectNotify(signal);
    }
    Shiboken::GilState gil;
    if (PyErr_Occurred())
        return;
    static PyObject *nameCache[2] = {};
    static const char *funcName = "disconnectNotify";
    Shiboken::AutoDecRef pyOverride(Shiboken::BindingManager::instance().getOverride(this, nameCache, funcName));
    if (pyOverride.isNull()) {
        gil.release();
        m_PyMethodCache[3] = true;
        return this->::QObject::disconnectNotify(signal);
    }

    Shiboken::AutoDecRef pyArgs(Py_BuildValue("(N)",
        Shiboken::Conversions::copyToPython(SbkPySide6_QtCoreTypes[SBK_QMETAMETHOD_IDX], &signal)
    ));

    Shiboken::AutoDecRef pyResult(PyObject_Call(pyOverride, pyArgs, nullptr));
    if (pyResult.isNull()) {
        // An error happened in python code!
        PyErr_Print();
        return;
    }
}

bool QThreadPoolWrapper::event(QEvent * event)
{
    if (m_PyMethodCache[4])
        return this->::QObject::event(event);
    Shiboken::GilState gil;
    if (PyErr_Occurred())
        return false;
    static PyObject *nameCache[2] = {};
    static const char *funcName = "event";
    Shiboken::AutoDecRef pyOverride(Shiboken::BindingManager::instance().getOverride(this, nameCache, funcName));
    if (pyOverride.isNull()) {
        gil.release();
        m_PyMethodCache[4] = true;
        return this->::QObject::event(event);
    }

    Shiboken::AutoDecRef pyArgs(Py_BuildValue("(N)",
        Shiboken::Conversions::pointerToPython(SbkPySide6_QtCoreTypes[SBK_QEVENT_IDX], event)
    ));
    bool invalidateArg1 = PyTuple_GET_ITEM(pyArgs, 0)->ob_refcnt == 1;

    Shiboken::AutoDecRef pyResult(PyObject_Call(pyOverride, pyArgs, nullptr));
    if (invalidateArg1)
        Shiboken::Object::invalidate(PyTuple_GET_ITEM(pyArgs, 0));
    if (pyResult.isNull()) {
        // An error happened in python code!
        PyErr_Print();
        return false;
    }
    // Check return type
    Shiboken::Conversions::PythonToCppConversion pythonToCpp =
        Shiboken::Conversions::pythonToCppConversion(Shiboken::Conversions::PrimitiveTypeConverter<bool>(), pyResult);
    if (!pythonToCpp) {
        Shiboken::warning(PyExc_RuntimeWarning, 2,
            "Invalid return value in function %s, expected %s, got %s.",
            "QThreadPool.event",
            "bool",
            Py_TYPE(pyResult)->tp_name);
        return false;
    }
    bool cppResult;
    pythonToCpp(pyResult, &cppResult);
    return cppResult;
}

bool QThreadPoolWrapper::eventFilter(QObject * watched, QEvent * event)
{
    if (m_PyMethodCache[5])
        return this->::QObject::eventFilter(watched, event);
    Shiboken::GilState gil;
    if (PyErr_Occurred())
        return false;
    static PyObject *nameCache[2] = {};
    static const char *funcName = "eventFilter";
    Shiboken::AutoDecRef pyOverride(Shiboken::BindingManager::instance().getOverride(this, nameCache, funcName));
    if (pyOverride.isNull()) {
        gil.release();
        m_PyMethodCache[5] = true;
        return this->::QObject::eventFilter(watched, event);
    }

    Shiboken::AutoDecRef pyArgs(Py_BuildValue("(NN)",
        Shiboken::Conversions::pointerToPython(SbkPySide6_QtCoreTypes[SBK_QOBJECT_IDX], watched),
        Shiboken::Conversions::pointerToPython(SbkPySide6_QtCoreTypes[SBK_QEVENT_IDX], event)
    ));
    bool invalidateArg2 = PyTuple_GET_ITEM(pyArgs, 1)->ob_refcnt == 1;

    Shiboken::AutoDecRef pyResult(PyObject_Call(pyOverride, pyArgs, nullptr));
    if (invalidateArg2)
        Shiboken::Object::invalidate(PyTuple_GET_ITEM(pyArgs, 1));
    if (pyResult.isNull()) {
        // An error happened in python code!
        PyErr_Print();
        return false;
    }
    // Check return type
    Shiboken::Conversions::PythonToCppConversion pythonToCpp =
        Shiboken::Conversions::pythonToCppConversion(Shiboken::Conversions::PrimitiveTypeConverter<bool>(), pyResult);
    if (!pythonToCpp) {
        Shiboken::warning(PyExc_RuntimeWarning, 2,
            "Invalid return value in function %s, expected %s, got %s.",
            "QThreadPool.eventFilter",
            "bool",
            Py_TYPE(pyResult)->tp_name);
        return false;
    }
    bool cppResult;
    pythonToCpp(pyResult, &cppResult);
    return cppResult;
}

void QThreadPoolWrapper::timerEvent(QTimerEvent * event)
{
    if (m_PyMethodCache[7]) {
        return this->::QObject::timerEvent(event);
    }
    Shiboken::GilState gil;
    if (PyErr_Occurred())
        return;
    static PyObject *nameCache[2] = {};
    static const char *funcName = "timerEvent";
    Shiboken::AutoDecRef pyOverride(Shiboken::BindingManager::instance().getOverride(this, nameCache, funcName));
    if (pyOverride.isNull()) {
        gil.release();
        m_PyMethodCache[7] = true;
        return this->::QObject::timerEvent(event);
    }

    Shiboken::AutoDecRef pyArgs(Py_BuildValue("(N)",
        Shiboken::Conversions::pointerToPython(SbkPySide6_QtCoreTypes[SBK_QTIMEREVENT_IDX], event)
    ));
    bool invalidateArg1 = PyTuple_GET_ITEM(pyArgs, 0)->ob_refcnt == 1;

    Shiboken::AutoDecRef pyResult(PyObject_Call(pyOverride, pyArgs, nullptr));
    if (invalidateArg1)
        Shiboken::Object::invalidate(PyTuple_GET_ITEM(pyArgs, 0));
    if (pyResult.isNull()) {
        // An error happened in python code!
        PyErr_Print();
        return;
    }
}

const QMetaObject *QThreadPoolWrapper::metaObject() const
{
    if (QObject::d_ptr->metaObject)
        return QObject::d_ptr->dynamicMetaObject();
    SbkObject *pySelf = Shiboken::BindingManager::instance().retrieveWrapper(this);
    if (pySelf == nullptr)
        return QThreadPool::metaObject();
    return PySide::SignalManager::retrieveMetaObject(reinterpret_cast<PyObject *>(pySelf));
}

int QThreadPoolWrapper::qt_metacall(QMetaObject::Call call, int id, void **args)
{
    int result = QThreadPool::qt_metacall(call, id, args);
    return result < 0 ? result : PySide::SignalManager::qt_metacall(this, call, id, args);
}

void *QThreadPoolWrapper::qt_metacast(const char *_clname)
{
    if (!_clname)
        return {};
    SbkObject *pySelf = Shiboken::BindingManager::instance().retrieveWrapper(this);
    if (pySelf && PySide::inherits(Py_TYPE(pySelf), _clname))
        return static_cast<void *>(const_cast< QThreadPoolWrapper *>(this));
    return QThreadPool::qt_metacast(_clname);
}

QThreadPoolWrapper::~QThreadPoolWrapper()
{
    SbkObject *wrapper = Shiboken::BindingManager::instance().retrieveWrapper(this);
    Shiboken::Object::destroy(wrapper, this);
}

// Target ---------------------------------------------------------

extern "C" {
static int
Sbk_QThreadPool_Init(PyObject *self, PyObject *args, PyObject *kwds)
{
    const QMetaObject *metaObject;
    SbkObject *sbkSelf = reinterpret_cast<SbkObject *>(self);
    PySide::Feature::Select(self);
    if (Shiboken::Object::isUserType(self) && !Shiboken::ObjectType::canCallConstructor(self->ob_type, Shiboken::SbkType< ::QThreadPool >()))
        return -1;

    ::QThreadPoolWrapper *cptr{};
    Shiboken::AutoDecRef errInfo{};
    static const char *fullName = "PySide6.QtCore.QThreadPool.__init__";
    SBK_UNUSED(fullName)
    int overloadId = -1;
    Shiboken::Conversions::PythonToCppConversion pythonToCpp[1];
    SBK_UNUSED(pythonToCpp)
    const Py_ssize_t numArgs = PyTuple_GET_SIZE(args);
    SBK_UNUSED(numArgs)
    PyObject *pyArgs[] = {0};

    // invalid argument lengths


    if (!PyArg_ParseTuple(args, "|O:QThreadPool", &(pyArgs[0])))
        return -1;


    // Overloaded function decisor
    // 0: QThreadPool::QThreadPool(QObject*)
    if (numArgs == 0) {
        overloadId = 0; // QThreadPool(QObject*)
    } else if (numArgs >= 1
        && (pythonToCpp[0] = Shiboken::Conversions::pythonToCppPointerConversion(SbkPySide6_QtCoreTypes[SBK_QOBJECT_IDX], (pyArgs[0])))) {
        overloadId = 0; // QThreadPool(QObject*)
    }

    // Function signature not found.
    if (overloadId == -1) goto Sbk_QThreadPool_Init_TypeError;

    // Call function/method
    {
        if (kwds && PyDict_Size(kwds) > 0) {
            PyObject *value{};
            Shiboken::AutoDecRef kwds_dup(PyDict_Copy(kwds));
            static PyObject *const key_parent = Shiboken::String::createStaticString("parent");
            if (PyDict_Contains(kwds, key_parent)) {
                value = PyDict_GetItem(kwds, key_parent);
                if (value && pyArgs[0]) {
                    errInfo.reset(key_parent);
                    Py_INCREF(errInfo.object());
                    goto Sbk_QThreadPool_Init_TypeError;
                }
                if (value) {
                    pyArgs[0] = value;
                    if (!(pythonToCpp[0] = Shiboken::Conversions::pythonToCppPointerConversion(SbkPySide6_QtCoreTypes[SBK_QOBJECT_IDX], (pyArgs[0]))))
                        goto Sbk_QThreadPool_Init_TypeError;
                }
                PyDict_DelItem(kwds_dup, key_parent);
            }
            if (PyDict_Size(kwds_dup) > 0) {
                errInfo.reset(kwds_dup.release());
                // fall through to handle extra keyword signals and properties
            }
        }
        if (!Shiboken::Object::isValid(pyArgs[0]))
            return -1;
        ::QObject *cppArg0 = nullptr;
        if (pythonToCpp[0])
            pythonToCpp[0](pyArgs[0], &cppArg0);

        if (!PyErr_Occurred()) {
            // QThreadPool(QObject*)
            void *addr = PySide::nextQObjectMemoryAddr();
            if (addr) {
                cptr = new (addr) ::QThreadPoolWrapper(cppArg0);
                PySide::setNextQObjectMemoryAddr(0);
            } else {
                cptr = new ::QThreadPoolWrapper(cppArg0);
            }

            Shiboken::Object::setParent(pyArgs[0], self);
        }
    }

    if (PyErr_Occurred() || !Shiboken::Object::setCppPointer(sbkSelf, Shiboken::SbkType< ::QThreadPool >(), cptr)) {
        delete cptr;
        return -1;
    }
    if (!cptr) goto Sbk_QThreadPool_Init_TypeError;

    Shiboken::Object::setValidCpp(sbkSelf, true);
    Shiboken::Object::setHasCppWrapper(sbkSelf, true);
    if (Shiboken::BindingManager::instance().hasWrapper(cptr)) {
        Shiboken::BindingManager::instance().releaseWrapper(Shiboken::BindingManager::instance().retrieveWrapper(cptr));
    }
    Shiboken::BindingManager::instance().registerWrapper(sbkSelf, cptr);

    // QObject setup
    PySide::Signal::updateSourceObject(self);
    metaObject = cptr->metaObject(); // <- init python qt properties
    if (!errInfo.isNull() && PyDict_Check(errInfo.object())) {
        if (!PySide::fillQtProperties(self, metaObject, errInfo))
            goto Sbk_QThreadPool_Init_TypeError;
    };


    return 1;

    Sbk_QThreadPool_Init_TypeError:
        Shiboken::setErrorAboutWrongArguments(args, fullName, errInfo);
        return -1;
}

static PyObject *Sbk_QThreadPoolFunc_activeThreadCount(PyObject *self)
{
    if (!Shiboken::Object::isValid(self))
        return {};
    auto cppSelf = reinterpret_cast< ::QThreadPool *>(Shiboken::Conversions::cppPointer(SbkPySide6_QtCoreTypes[SBK_QTHREADPOOL_IDX], reinterpret_cast<SbkObject *>(self)));
    SBK_UNUSED(cppSelf)
    PyObject *pyResult{};
    Shiboken::AutoDecRef errInfo{};
    static const char *fullName = "PySide6.QtCore.QThreadPool.activeThreadCount";
    SBK_UNUSED(fullName)

    // Call function/method
    {

        if (!PyErr_Occurred()) {
            // activeThreadCount()const
            PyThreadState *_save = PyEval_SaveThread(); // Py_BEGIN_ALLOW_THREADS
            int cppResult = const_cast<const ::QThreadPool *>(cppSelf)->activeThreadCount();
            PyEval_RestoreThread(_save); // Py_END_ALLOW_THREADS
            pyResult = Shiboken::Conversions::copyToPython(Shiboken::Conversions::PrimitiveTypeConverter<int>(), &cppResult);
        }
    }

    if (PyErr_Occurred() || !pyResult) {
        Py_XDECREF(pyResult);
        return {};
    }
    return pyResult;
}

static PyObject *Sbk_QThreadPoolFunc_clear(PyObject *self)
{
    if (!Shiboken::Object::isValid(self))
        return {};
    auto cppSelf = reinterpret_cast< ::QThreadPool *>(Shiboken::Conversions::cppPointer(SbkPySide6_QtCoreTypes[SBK_QTHREADPOOL_IDX], reinterpret_cast<SbkObject *>(self)));
    SBK_UNUSED(cppSelf)
    Shiboken::AutoDecRef errInfo{};
    static const char *fullName = "PySide6.QtCore.QThreadPool.clear";
    SBK_UNUSED(fullName)

    // Call function/method
    {

        if (!PyErr_Occurred()) {
            // clear()
            PyThreadState *_save = PyEval_SaveThread(); // Py_BEGIN_ALLOW_THREADS
            cppSelf->clear();
            PyEval_RestoreThread(_save); // Py_END_ALLOW_THREADS
        }
    }

    if (PyErr_Occurred()) {
        return {};
    }
    Py_RETURN_NONE;
}

static PyObject *Sbk_QThreadPoolFunc_contains(PyObject *self, PyObject *pyArg)
{
    if (!Shiboken::Object::isValid(self))
        return {};
    auto cppSelf = reinterpret_cast< ::QThreadPool *>(Shiboken::Conversions::cppPointer(SbkPySide6_QtCoreTypes[SBK_QTHREADPOOL_IDX], reinterpret_cast<SbkObject *>(self)));
    SBK_UNUSED(cppSelf)
    PyObject *pyResult{};
    Shiboken::AutoDecRef errInfo{};
    static const char *fullName = "PySide6.QtCore.QThreadPool.contains";
    SBK_UNUSED(fullName)
    int overloadId = -1;
    Shiboken::Conversions::PythonToCppConversion pythonToCpp;
    SBK_UNUSED(pythonToCpp)

    // Overloaded function decisor
    // 0: QThreadPool::contains(const QThread*)const->bool
    if ((pythonToCpp = Shiboken::Conversions::pythonToCppPointerConversion(SbkPySide6_QtCoreTypes[SBK_QTHREAD_IDX], (pyArg)))) {
        overloadId = 0; // contains(const QThread*)const
    }

    // Function signature not found.
    if (overloadId == -1) goto Sbk_QThreadPoolFunc_contains_TypeError;

    // Call function/method
    {
        if (!Shiboken::Object::isValid(pyArg))
            return {};
        ::QThread *cppArg0;
        pythonToCpp(pyArg, &cppArg0);

        if (!PyErr_Occurred()) {
            // contains(const QThread*)const
            bool cppResult = const_cast<const ::QThreadPool *>(cppSelf)->contains(cppArg0);
            pyResult = Shiboken::Conversions::copyToPython(Shiboken::Conversions::PrimitiveTypeConverter<bool>(), &cppResult);
        }
    }

    if (PyErr_Occurred() || !pyResult) {
        Py_XDECREF(pyResult);
        return {};
    }
    return pyResult;

    Sbk_QThreadPoolFunc_contains_TypeError:
        Shiboken::setErrorAboutWrongArguments(pyArg, fullName, errInfo);
        return {};
}

static PyObject *Sbk_QThreadPoolFunc_expiryTimeout(PyObject *self)
{
    if (!Shiboken::Object::isValid(self))
        return {};
    auto cppSelf = reinterpret_cast< ::QThreadPool *>(Shiboken::Conversions::cppPointer(SbkPySide6_QtCoreTypes[SBK_QTHREADPOOL_IDX], reinterpret_cast<SbkObject *>(self)));
    SBK_UNUSED(cppSelf)
    PyObject *pyResult{};
    Shiboken::AutoDecRef errInfo{};
    static const char *fullName = "PySide6.QtCore.QThreadPool.expiryTimeout";
    SBK_UNUSED(fullName)

    // Call function/method
    {

        if (!PyErr_Occurred()) {
            // expiryTimeout()const
            int cppResult = const_cast<const ::QThreadPool *>(cppSelf)->expiryTimeout();
            pyResult = Shiboken::Conversions::copyToPython(Shiboken::Conversions::PrimitiveTypeConverter<int>(), &cppResult);
        }
    }

    if (PyErr_Occurred() || !pyResult) {
        Py_XDECREF(pyResult);
        return {};
    }
    return pyResult;
}

static PyObject *Sbk_QThreadPoolFunc_globalInstance(PyObject *self)
{
    PyObject *pyResult{};
    Shiboken::AutoDecRef errInfo{};
    static const char *fullName = "PySide6.QtCore.QThreadPool.globalInstance";
    SBK_UNUSED(fullName)

    // Call function/method
    {

        if (!PyErr_Occurred()) {
            // globalInstance()
            QThreadPool * cppResult = ::QThreadPool::globalInstance();
            pyResult = Shiboken::Conversions::pointerToPython(SbkPySide6_QtCoreTypes[SBK_QTHREADPOOL_IDX], cppResult);
            // Begin code injection
            // ========================================================================
            // START of custom code block [file: ../glue/qtcore.cpp (releaseownership)]
            Shiboken::Object::releaseOwnership(pyResult);
            // END of custom code block [file: ../glue/qtcore.cpp (releaseownership)]
            // ========================================================================
            // End of code injection

        }
    }

    if (PyErr_Occurred() || !pyResult) {
        Py_XDECREF(pyResult);
        return {};
    }
    return pyResult;
}

static PyObject *Sbk_QThreadPoolFunc_maxThreadCount(PyObject *self)
{
    if (!Shiboken::Object::isValid(self))
        return {};
    auto cppSelf = reinterpret_cast< ::QThreadPool *>(Shiboken::Conversions::cppPointer(SbkPySide6_QtCoreTypes[SBK_QTHREADPOOL_IDX], reinterpret_cast<SbkObject *>(self)));
    SBK_UNUSED(cppSelf)
    PyObject *pyResult{};
    Shiboken::AutoDecRef errInfo{};
    static const char *fullName = "PySide6.QtCore.QThreadPool.maxThreadCount";
    SBK_UNUSED(fullName)

    // Call function/method
    {

        if (!PyErr_Occurred()) {
            // maxThreadCount()const
            int cppResult = const_cast<const ::QThreadPool *>(cppSelf)->maxThreadCount();
            pyResult = Shiboken::Conversions::copyToPython(Shiboken::Conversions::PrimitiveTypeConverter<int>(), &cppResult);
        }
    }

    if (PyErr_Occurred() || !pyResult) {
        Py_XDECREF(pyResult);
        return {};
    }
    return pyResult;
}

static PyObject *Sbk_QThreadPoolFunc_releaseThread(PyObject *self)
{
    if (!Shiboken::Object::isValid(self))
        return {};
    auto cppSelf = reinterpret_cast< ::QThreadPool *>(Shiboken::Conversions::cppPointer(SbkPySide6_QtCoreTypes[SBK_QTHREADPOOL_IDX], reinterpret_cast<SbkObject *>(self)));
    SBK_UNUSED(cppSelf)
    Shiboken::AutoDecRef errInfo{};
    static const char *fullName = "PySide6.QtCore.QThreadPool.releaseThread";
    SBK_UNUSED(fullName)

    // Call function/method
    {

        if (!PyErr_Occurred()) {
            // releaseThread()
            PyThreadState *_save = PyEval_SaveThread(); // Py_BEGIN_ALLOW_THREADS
            cppSelf->releaseThread();
            PyEval_RestoreThread(_save); // Py_END_ALLOW_THREADS
        }
    }

    if (PyErr_Occurred()) {
        return {};
    }
    Py_RETURN_NONE;
}

static PyObject *Sbk_QThreadPoolFunc_reserveThread(PyObject *self)
{
    if (!Shiboken::Object::isValid(self))
        return {};
    auto cppSelf = reinterpret_cast< ::QThreadPool *>(Shiboken::Conversions::cppPointer(SbkPySide6_QtCoreTypes[SBK_QTHREADPOOL_IDX], reinterpret_cast<SbkObject *>(self)));
    SBK_UNUSED(cppSelf)
    Shiboken::AutoDecRef errInfo{};
    static const char *fullName = "PySide6.QtCore.QThreadPool.reserveThread";
    SBK_UNUSED(fullName)

    // Call function/method
    {

        if (!PyErr_Occurred()) {
            // reserveThread()
            PyThreadState *_save = PyEval_SaveThread(); // Py_BEGIN_ALLOW_THREADS
            cppSelf->reserveThread();
            PyEval_RestoreThread(_save); // Py_END_ALLOW_THREADS
        }
    }

    if (PyErr_Occurred()) {
        return {};
    }
    Py_RETURN_NONE;
}

static PyObject *Sbk_QThreadPoolFunc_setExpiryTimeout(PyObject *self, PyObject *pyArg)
{
    if (!Shiboken::Object::isValid(self))
        return {};
    auto cppSelf = reinterpret_cast< ::QThreadPool *>(Shiboken::Conversions::cppPointer(SbkPySide6_QtCoreTypes[SBK_QTHREADPOOL_IDX], reinterpret_cast<SbkObject *>(self)));
    SBK_UNUSED(cppSelf)
    Shiboken::AutoDecRef errInfo{};
    static const char *fullName = "PySide6.QtCore.QThreadPool.setExpiryTimeout";
    SBK_UNUSED(fullName)
    int overloadId = -1;
    Shiboken::Conversions::PythonToCppConversion pythonToCpp;
    SBK_UNUSED(pythonToCpp)

    // Overloaded function decisor
    // 0: QThreadPool::setExpiryTimeout(int)
    if ((pythonToCpp = Shiboken::Conversions::pythonToCppConversion(Shiboken::Conversions::PrimitiveTypeConverter<int>(), (pyArg)))) {
        overloadId = 0; // setExpiryTimeout(int)
    }

    // Function signature not found.
    if (overloadId == -1) goto Sbk_QThreadPoolFunc_setExpiryTimeout_TypeError;

    // Call function/method
    {
        int cppArg0;
        pythonToCpp(pyArg, &cppArg0);

        if (!PyErr_Occurred()) {
            // setExpiryTimeout(int)
            cppSelf->setExpiryTimeout(cppArg0);
        }
    }

    if (PyErr_Occurred()) {
        return {};
    }
    Py_RETURN_NONE;

    Sbk_QThreadPoolFunc_setExpiryTimeout_TypeError:
        Shiboken::setErrorAboutWrongArguments(pyArg, fullName, errInfo);
        return {};
}

static PyObject *Sbk_QThreadPoolFunc_setMaxThreadCount(PyObject *self, PyObject *pyArg)
{
    if (!Shiboken::Object::isValid(self))
        return {};
    auto cppSelf = reinterpret_cast< ::QThreadPool *>(Shiboken::Conversions::cppPointer(SbkPySide6_QtCoreTypes[SBK_QTHREADPOOL_IDX], reinterpret_cast<SbkObject *>(self)));
    SBK_UNUSED(cppSelf)
    Shiboken::AutoDecRef errInfo{};
    static const char *fullName = "PySide6.QtCore.QThreadPool.setMaxThreadCount";
    SBK_UNUSED(fullName)
    int overloadId = -1;
    Shiboken::Conversions::PythonToCppConversion pythonToCpp;
    SBK_UNUSED(pythonToCpp)

    // Overloaded function decisor
    // 0: QThreadPool::setMaxThreadCount(int)
    if ((pythonToCpp = Shiboken::Conversions::pythonToCppConversion(Shiboken::Conversions::PrimitiveTypeConverter<int>(), (pyArg)))) {
        overloadId = 0; // setMaxThreadCount(int)
    }

    // Function signature not found.
    if (overloadId == -1) goto Sbk_QThreadPoolFunc_setMaxThreadCount_TypeError;

    // Call function/method
    {
        int cppArg0;
        pythonToCpp(pyArg, &cppArg0);

        if (!PyErr_Occurred()) {
            // setMaxThreadCount(int)
            PyThreadState *_save = PyEval_SaveThread(); // Py_BEGIN_ALLOW_THREADS
            cppSelf->setMaxThreadCount(cppArg0);
            PyEval_RestoreThread(_save); // Py_END_ALLOW_THREADS
        }
    }

    if (PyErr_Occurred()) {
        return {};
    }
    Py_RETURN_NONE;

    Sbk_QThreadPoolFunc_setMaxThreadCount_TypeError:
        Shiboken::setErrorAboutWrongArguments(pyArg, fullName, errInfo);
        return {};
}

static PyObject *Sbk_QThreadPoolFunc_setStackSize(PyObject *self, PyObject *pyArg)
{
    if (!Shiboken::Object::isValid(self))
        return {};
    auto cppSelf = reinterpret_cast< ::QThreadPool *>(Shiboken::Conversions::cppPointer(SbkPySide6_QtCoreTypes[SBK_QTHREADPOOL_IDX], reinterpret_cast<SbkObject *>(self)));
    SBK_UNUSED(cppSelf)
    Shiboken::AutoDecRef errInfo{};
    static const char *fullName = "PySide6.QtCore.QThreadPool.setStackSize";
    SBK_UNUSED(fullName)
    int overloadId = -1;
    Shiboken::Conversions::PythonToCppConversion pythonToCpp;
    SBK_UNUSED(pythonToCpp)

    // Overloaded function decisor
    // 0: QThreadPool::setStackSize(uint)
    if ((pythonToCpp = Shiboken::Conversions::pythonToCppConversion(Shiboken::Conversions::PrimitiveTypeConverter<uint>(), (pyArg)))) {
        overloadId = 0; // setStackSize(uint)
    }

    // Function signature not found.
    if (overloadId == -1) goto Sbk_QThreadPoolFunc_setStackSize_TypeError;

    // Call function/method
    {
        uint cppArg0;
        pythonToCpp(pyArg, &cppArg0);

        if (!PyErr_Occurred()) {
            // setStackSize(uint)
            cppSelf->setStackSize(cppArg0);
        }
    }

    if (PyErr_Occurred()) {
        return {};
    }
    Py_RETURN_NONE;

    Sbk_QThreadPoolFunc_setStackSize_TypeError:
        Shiboken::setErrorAboutWrongArguments(pyArg, fullName, errInfo);
        return {};
}

static PyObject *Sbk_QThreadPoolFunc_setThreadPriority(PyObject *self, PyObject *pyArg)
{
    if (!Shiboken::Object::isValid(self))
        return {};
    auto cppSelf = reinterpret_cast< ::QThreadPool *>(Shiboken::Conversions::cppPointer(SbkPySide6_QtCoreTypes[SBK_QTHREADPOOL_IDX], reinterpret_cast<SbkObject *>(self)));
    SBK_UNUSED(cppSelf)
    Shiboken::AutoDecRef errInfo{};
    static const char *fullName = "PySide6.QtCore.QThreadPool.setThreadPriority";
    SBK_UNUSED(fullName)
    int overloadId = -1;
    Shiboken::Conversions::PythonToCppConversion pythonToCpp;
    SBK_UNUSED(pythonToCpp)

    // Overloaded function decisor
    // 0: QThreadPool::setThreadPriority(QThread::Priority)
    if ((pythonToCpp = Shiboken::Conversions::pythonToCppConversion(PepType_SETP(reinterpret_cast<SbkEnumType *>(SbkPySide6_QtCoreTypes[SBK_QTHREAD_PRIORITY_IDX]))->converter, (pyArg)))) {
        overloadId = 0; // setThreadPriority(QThread::Priority)
    }

    // Function signature not found.
    if (overloadId == -1) goto Sbk_QThreadPoolFunc_setThreadPriority_TypeError;

    // Call function/method
    {
        ::QThread::Priority cppArg0{QThread::IdlePriority};
        pythonToCpp(pyArg, &cppArg0);

        if (!PyErr_Occurred()) {
            // setThreadPriority(QThread::Priority)
            cppSelf->setThreadPriority(cppArg0);
        }
    }

    if (PyErr_Occurred()) {
        return {};
    }
    Py_RETURN_NONE;

    Sbk_QThreadPoolFunc_setThreadPriority_TypeError:
        Shiboken::setErrorAboutWrongArguments(pyArg, fullName, errInfo);
        return {};
}

static PyObject *Sbk_QThreadPoolFunc_stackSize(PyObject *self)
{
    if (!Shiboken::Object::isValid(self))
        return {};
    auto cppSelf = reinterpret_cast< ::QThreadPool *>(Shiboken::Conversions::cppPointer(SbkPySide6_QtCoreTypes[SBK_QTHREADPOOL_IDX], reinterpret_cast<SbkObject *>(self)));
    SBK_UNUSED(cppSelf)
    PyObject *pyResult{};
    Shiboken::AutoDecRef errInfo{};
    static const char *fullName = "PySide6.QtCore.QThreadPool.stackSize";
    SBK_UNUSED(fullName)

    // Call function/method
    {

        if (!PyErr_Occurred()) {
            // stackSize()const
            uint cppResult = const_cast<const ::QThreadPool *>(cppSelf)->stackSize();
            pyResult = Shiboken::Conversions::copyToPython(Shiboken::Conversions::PrimitiveTypeConverter<uint>(), &cppResult);
        }
    }

    if (PyErr_Occurred() || !pyResult) {
        Py_XDECREF(pyResult);
        return {};
    }
    return pyResult;
}

static PyObject *Sbk_QThreadPoolFunc_start(PyObject *self, PyObject *args, PyObject *kwds)
{
    if (!Shiboken::Object::isValid(self))
        return {};
    auto cppSelf = reinterpret_cast< ::QThreadPool *>(Shiboken::Conversions::cppPointer(SbkPySide6_QtCoreTypes[SBK_QTHREADPOOL_IDX], reinterpret_cast<SbkObject *>(self)));
    SBK_UNUSED(cppSelf)
    Shiboken::AutoDecRef errInfo{};
    static const char *fullName = "PySide6.QtCore.QThreadPool.start";
    SBK_UNUSED(fullName)
    int overloadId = -1;
    Shiboken::Conversions::PythonToCppConversion pythonToCpp[2];
    SBK_UNUSED(pythonToCpp)
    const Py_ssize_t numArgs = PyTuple_GET_SIZE(args);
    SBK_UNUSED(numArgs)
    PyObject *pyArgs[] = {0, 0};

    // invalid argument lengths
    if (numArgs > 2) {
        static PyObject *const too_many = Shiboken::String::createStaticString(">");
        errInfo.reset(too_many);
        Py_INCREF(errInfo.object());
        goto Sbk_QThreadPoolFunc_start_TypeError;
    } else if (numArgs < 1) {
        static PyObject *const too_few = Shiboken::String::createStaticString("<");
        errInfo.reset(too_few);
        Py_INCREF(errInfo.object());
        goto Sbk_QThreadPoolFunc_start_TypeError;
    }

    if (!PyArg_ParseTuple(args, "|OO:start", &(pyArgs[0]), &(pyArgs[1])))
        return {};


    // Overloaded function decisor
    // 0: QThreadPool::start(PyCallable,int)
    // 1: QThreadPool::start(QRunnable*,int)
    if (numArgs >= 1
        && (pythonToCpp[0] = Shiboken::Conversions::pythonToCppPointerConversion(SbkPySide6_QtCoreTypes[SBK_QRUNNABLE_IDX], (pyArgs[0])))) {
        if (numArgs == 1) {
            overloadId = 1; // start(QRunnable*,int)
        } else if (numArgs >= 2
            && (pythonToCpp[1] = Shiboken::Conversions::pythonToCppConversion(Shiboken::Conversions::PrimitiveTypeConverter<int>(), (pyArgs[1])))) {
            overloadId = 1; // start(QRunnable*,int)
        }
    } else if (numArgs >= 1
        && PyCallable_Check(pyArgs[0])) {
        if (numArgs == 1) {
            overloadId = 0; // start(PyCallable,int)
        } else if (numArgs >= 2
            && (pythonToCpp[1] = Shiboken::Conversions::pythonToCppConversion(Shiboken::Conversions::PrimitiveTypeConverter<int>(), (pyArgs[1])))) {
            overloadId = 0; // start(PyCallable,int)
        }
    }

    // Function signature not found.
    if (overloadId == -1) goto Sbk_QThreadPoolFunc_start_TypeError;

    // Call function/method
    switch (overloadId) {
        case 0: // start(PyCallable arg__1, int priority)
        {
            if (kwds && PyDict_Size(kwds) > 0) {
                PyObject *value{};
                Shiboken::AutoDecRef kwds_dup(PyDict_Copy(kwds));
                static PyObject *const key_priority = Shiboken::String::createStaticString("priority");
                if (PyDict_Contains(kwds, key_priority)) {
                    value = PyDict_GetItem(kwds, key_priority);
                    if (value && pyArgs[1]) {
                        errInfo.reset(key_priority);
                        Py_INCREF(errInfo.object());
                        goto Sbk_QThreadPoolFunc_start_TypeError;
                    }
                    if (value) {
                        pyArgs[1] = value;
                        if (!(pythonToCpp[1] = Shiboken::Conversions::pythonToCppConversion(Shiboken::Conversions::PrimitiveTypeConverter<int>(), (pyArgs[1]))))
                            goto Sbk_QThreadPoolFunc_start_TypeError;
                    }
                    PyDict_DelItem(kwds_dup, key_priority);
                }
                if (PyDict_Size(kwds_dup) > 0) {
                    errInfo.reset(kwds_dup.release());
                    goto Sbk_QThreadPoolFunc_start_TypeError;
                }
            }
            int cppArg1 = 0;
            if (pythonToCpp[1])
                pythonToCpp[1](pyArgs[1], &cppArg1);
            SBK_UNUSED(cppArg1)

            if (!PyErr_Occurred()) {
                // start(PyCallable,int)
                // Begin code injection
                // ========================================================================
                // START of custom code block [file: ../glue/qtcore.cpp (std-function-void-lambda)]
                auto *callable = pyArgs[1-1];
                auto cppCallback = [callable]()
                {
                    Shiboken::GilState state;
                    Shiboken::AutoDecRef arglist(PyTuple_New(0));
                    Shiboken::AutoDecRef ret(PyObject_CallObject(callable, arglist));
                    Py_DECREF(callable);
                };
                // END of custom code block [file: ../glue/qtcore.cpp (std-function-void-lambda)]
                // ========================================================================
                // ========================================================================
                // START of custom code block [file: ../glue/qtcore.cpp (qthreadpool-start)]
                Py_INCREF(callable);
                cppSelf->start(cppCallback, cppArg1);
                // END of custom code block [file: ../glue/qtcore.cpp (qthreadpool-start)]
                // ========================================================================
                // End of code injection

            }
            break;
        }
        case 1: // start(QRunnable * runnable, int priority)
        {
            if (kwds && PyDict_Size(kwds) > 0) {
                PyObject *value{};
                Shiboken::AutoDecRef kwds_dup(PyDict_Copy(kwds));
                static PyObject *const key_priority = Shiboken::String::createStaticString("priority");
                if (PyDict_Contains(kwds, key_priority)) {
                    value = PyDict_GetItem(kwds, key_priority);
                    if (value && pyArgs[1]) {
                        errInfo.reset(key_priority);
                        Py_INCREF(errInfo.object());
                        goto Sbk_QThreadPoolFunc_start_TypeError;
                    }
                    if (value) {
                        pyArgs[1] = value;
                        if (!(pythonToCpp[1] = Shiboken::Conversions::pythonToCppConversion(Shiboken::Conversions::PrimitiveTypeConverter<int>(), (pyArgs[1]))))
                            goto Sbk_QThreadPoolFunc_start_TypeError;
                    }
                    PyDict_DelItem(kwds_dup, key_priority);
                }
                if (PyDict_Size(kwds_dup) > 0) {
                    errInfo.reset(kwds_dup.release());
                    goto Sbk_QThreadPoolFunc_start_TypeError;
                }
            }
            if (!Shiboken::Object::isValid(pyArgs[0]))
                return {};
            ::QRunnable *cppArg0;
            pythonToCpp[0](pyArgs[0], &cppArg0);
            int cppArg1 = 0;
            if (pythonToCpp[1])
                pythonToCpp[1](pyArgs[1], &cppArg1);

            if (!PyErr_Occurred()) {
                // start(QRunnable*,int)
                PyThreadState *_save = PyEval_SaveThread(); // Py_BEGIN_ALLOW_THREADS
                cppSelf->start(cppArg0, cppArg1);
                PyEval_RestoreThread(_save); // Py_END_ALLOW_THREADS
                Shiboken::Object::setParent(self, pyArgs[0]);
            }
            break;
        }
    }

    if (PyErr_Occurred()) {
        return {};
    }
    Py_RETURN_NONE;

    Sbk_QThreadPoolFunc_start_TypeError:
        Shiboken::setErrorAboutWrongArguments(args, fullName, errInfo);
        return {};
}

static PyObject *Sbk_QThreadPoolFunc_threadPriority(PyObject *self)
{
    if (!Shiboken::Object::isValid(self))
        return {};
    auto cppSelf = reinterpret_cast< ::QThreadPool *>(Shiboken::Conversions::cppPointer(SbkPySide6_QtCoreTypes[SBK_QTHREADPOOL_IDX], reinterpret_cast<SbkObject *>(self)));
    SBK_UNUSED(cppSelf)
    PyObject *pyResult{};
    Shiboken::AutoDecRef errInfo{};
    static const char *fullName = "PySide6.QtCore.QThreadPool.threadPriority";
    SBK_UNUSED(fullName)

    // Call function/method
    {

        if (!PyErr_Occurred()) {
            // threadPriority()const
            QThread::Priority cppResult = const_cast<const ::QThreadPool *>(cppSelf)->threadPriority();
            pyResult = Shiboken::Conversions::copyToPython(PepType_SETP(reinterpret_cast<SbkEnumType *>(SbkPySide6_QtCoreTypes[SBK_QTHREAD_PRIORITY_IDX]))->converter, &cppResult);
        }
    }

    if (PyErr_Occurred() || !pyResult) {
        Py_XDECREF(pyResult);
        return {};
    }
    return pyResult;
}

static PyObject *Sbk_QThreadPoolFunc_tryStart(PyObject *self, PyObject *pyArg)
{
    if (!Shiboken::Object::isValid(self))
        return {};
    auto cppSelf = reinterpret_cast< ::QThreadPool *>(Shiboken::Conversions::cppPointer(SbkPySide6_QtCoreTypes[SBK_QTHREADPOOL_IDX], reinterpret_cast<SbkObject *>(self)));
    SBK_UNUSED(cppSelf)
    PyObject *pyResult{};
    Shiboken::AutoDecRef errInfo{};
    static const char *fullName = "PySide6.QtCore.QThreadPool.tryStart";
    SBK_UNUSED(fullName)
    int overloadId = -1;
    Shiboken::Conversions::PythonToCppConversion pythonToCpp;
    SBK_UNUSED(pythonToCpp)

    // Overloaded function decisor
    // 0: QThreadPool::tryStart(PyCallable)->bool
    // 1: QThreadPool::tryStart(QRunnable*)->bool
    if ((pythonToCpp = Shiboken::Conversions::pythonToCppPointerConversion(SbkPySide6_QtCoreTypes[SBK_QRUNNABLE_IDX], (pyArg)))) {
        overloadId = 1; // tryStart(QRunnable*)
    } else if (PyCallable_Check(pyArg)) {
        overloadId = 0; // tryStart(PyCallable)
    }

    // Function signature not found.
    if (overloadId == -1) goto Sbk_QThreadPoolFunc_tryStart_TypeError;

    // Call function/method
    switch (overloadId) {
        case 0: // tryStart(PyCallable arg__1)
        {

            if (!PyErr_Occurred()) {
                // tryStart(PyCallable)
                // Begin code injection
                // ========================================================================
                // START of custom code block [file: ../glue/qtcore.cpp (std-function-void-lambda)]
                auto *callable = pyArg;
                auto cppCallback = [callable]()
                {
                    Shiboken::GilState state;
                    Shiboken::AutoDecRef arglist(PyTuple_New(0));
                    Shiboken::AutoDecRef ret(PyObject_CallObject(callable, arglist));
                    Py_DECREF(callable);
                };
                // END of custom code block [file: ../glue/qtcore.cpp (std-function-void-lambda)]
                // ========================================================================
                // ========================================================================
                // START of custom code block [file: ../glue/qtcore.cpp (qthreadpool-trystart)]
                Py_INCREF(callable);
                bool cppResult = cppSelf->tryStart(cppCallback);
                pyResult = Shiboken::Conversions::copyToPython(Shiboken::Conversions::PrimitiveTypeConverter<int>(), &cppResult);
                // END of custom code block [file: ../glue/qtcore.cpp (qthreadpool-trystart)]
                // ========================================================================
                // End of code injection

            }
            break;
        }
        case 1: // tryStart(QRunnable * runnable)
        {
            if (!Shiboken::Object::isValid(pyArg))
                return {};
            ::QRunnable *cppArg0;
            pythonToCpp(pyArg, &cppArg0);

            if (!PyErr_Occurred()) {
                // tryStart(QRunnable*)
                PyThreadState *_save = PyEval_SaveThread(); // Py_BEGIN_ALLOW_THREADS
                bool cppResult = cppSelf->tryStart(cppArg0);
                PyEval_RestoreThread(_save); // Py_END_ALLOW_THREADS
                pyResult = Shiboken::Conversions::copyToPython(Shiboken::Conversions::PrimitiveTypeConverter<bool>(), &cppResult);
                Shiboken::Object::setParent(self, pyArg);
            }
            break;
        }
    }

    if (PyErr_Occurred() || !pyResult) {
        Py_XDECREF(pyResult);
        return {};
    }
    return pyResult;

    Sbk_QThreadPoolFunc_tryStart_TypeError:
        Shiboken::setErrorAboutWrongArguments(pyArg, fullName, errInfo);
        return {};
}

static PyObject *Sbk_QThreadPoolFunc_tryTake(PyObject *self, PyObject *pyArg)
{
    if (!Shiboken::Object::isValid(self))
        return {};
    auto cppSelf = reinterpret_cast< ::QThreadPool *>(Shiboken::Conversions::cppPointer(SbkPySide6_QtCoreTypes[SBK_QTHREADPOOL_IDX], reinterpret_cast<SbkObject *>(self)));
    SBK_UNUSED(cppSelf)
    PyObject *pyResult{};
    Shiboken::AutoDecRef errInfo{};
    static const char *fullName = "PySide6.QtCore.QThreadPool.tryTake";
    SBK_UNUSED(fullName)
    int overloadId = -1;
    Shiboken::Conversions::PythonToCppConversion pythonToCpp;
    SBK_UNUSED(pythonToCpp)

    // Overloaded function decisor
    // 0: QThreadPool::tryTake(QRunnable*)->bool
    if ((pythonToCpp = Shiboken::Conversions::pythonToCppPointerConversion(SbkPySide6_QtCoreTypes[SBK_QRUNNABLE_IDX], (pyArg)))) {
        overloadId = 0; // tryTake(QRunnable*)
    }

    // Function signature not found.
    if (overloadId == -1) goto Sbk_QThreadPoolFunc_tryTake_TypeError;

    // Call function/method
    {
        if (!Shiboken::Object::isValid(pyArg))
            return {};
        ::QRunnable *cppArg0;
        pythonToCpp(pyArg, &cppArg0);

        if (!PyErr_Occurred()) {
            // tryTake(QRunnable*)
            PyThreadState *_save = PyEval_SaveThread(); // Py_BEGIN_ALLOW_THREADS
            bool cppResult = cppSelf->tryTake(cppArg0);
            PyEval_RestoreThread(_save); // Py_END_ALLOW_THREADS
            pyResult = Shiboken::Conversions::copyToPython(Shiboken::Conversions::PrimitiveTypeConverter<bool>(), &cppResult);
        }
    }

    if (PyErr_Occurred() || !pyResult) {
        Py_XDECREF(pyResult);
        return {};
    }
    return pyResult;

    Sbk_QThreadPoolFunc_tryTake_TypeError:
        Shiboken::setErrorAboutWrongArguments(pyArg, fullName, errInfo);
        return {};
}

static PyObject *Sbk_QThreadPoolFunc_waitForDone(PyObject *self, PyObject *args, PyObject *kwds)
{
    if (!Shiboken::Object::isValid(self))
        return {};
    auto cppSelf = reinterpret_cast< ::QThreadPool *>(Shiboken::Conversions::cppPointer(SbkPySide6_QtCoreTypes[SBK_QTHREADPOOL_IDX], reinterpret_cast<SbkObject *>(self)));
    SBK_UNUSED(cppSelf)
    PyObject *pyResult{};
    Shiboken::AutoDecRef errInfo{};
    static const char *fullName = "PySide6.QtCore.QThreadPool.waitForDone";
    SBK_UNUSED(fullName)
    int overloadId = -1;
    Shiboken::Conversions::PythonToCppConversion pythonToCpp[1];
    SBK_UNUSED(pythonToCpp)
    const Py_ssize_t numArgs = PyTuple_GET_SIZE(args);
    SBK_UNUSED(numArgs)
    PyObject *pyArgs[] = {0};

    // invalid argument lengths
    if (numArgs > 1) {
        static PyObject *const too_many = Shiboken::String::createStaticString(">");
        errInfo.reset(too_many);
        Py_INCREF(errInfo.object());
        goto Sbk_QThreadPoolFunc_waitForDone_TypeError;
    }

    if (!PyArg_ParseTuple(args, "|O:waitForDone", &(pyArgs[0])))
        return {};


    // Overloaded function decisor
    // 0: QThreadPool::waitForDone(int)->bool
    if (numArgs == 0) {
        overloadId = 0; // waitForDone(int)
    } else if (numArgs >= 1
        && (pythonToCpp[0] = Shiboken::Conversions::pythonToCppConversion(Shiboken::Conversions::PrimitiveTypeConverter<int>(), (pyArgs[0])))) {
        overloadId = 0; // waitForDone(int)
    }

    // Function signature not found.
    if (overloadId == -1) goto Sbk_QThreadPoolFunc_waitForDone_TypeError;

    // Call function/method
    {
        if (kwds && PyDict_Size(kwds) > 0) {
            PyObject *value{};
            Shiboken::AutoDecRef kwds_dup(PyDict_Copy(kwds));
            static PyObject *const key_msecs = Shiboken::String::createStaticString("msecs");
            if (PyDict_Contains(kwds, key_msecs)) {
                value = PyDict_GetItem(kwds, key_msecs);
                if (value && pyArgs[0]) {
                    errInfo.reset(key_msecs);
                    Py_INCREF(errInfo.object());
                    goto Sbk_QThreadPoolFunc_waitForDone_TypeError;
                }
                if (value) {
                    pyArgs[0] = value;
                    if (!(pythonToCpp[0] = Shiboken::Conversions::pythonToCppConversion(Shiboken::Conversions::PrimitiveTypeConverter<int>(), (pyArgs[0]))))
                        goto Sbk_QThreadPoolFunc_waitForDone_TypeError;
                }
                PyDict_DelItem(kwds_dup, key_msecs);
            }
            if (PyDict_Size(kwds_dup) > 0) {
                errInfo.reset(kwds_dup.release());
                goto Sbk_QThreadPoolFunc_waitForDone_TypeError;
            }
        }
        int cppArg0 = -1;
        if (pythonToCpp[0])
            pythonToCpp[0](pyArgs[0], &cppArg0);

        if (!PyErr_Occurred()) {
            // waitForDone(int)
            PyThreadState *_save = PyEval_SaveThread(); // Py_BEGIN_ALLOW_THREADS
            bool cppResult = cppSelf->waitForDone(cppArg0);
            PyEval_RestoreThread(_save); // Py_END_ALLOW_THREADS
            pyResult = Shiboken::Conversions::copyToPython(Shiboken::Conversions::PrimitiveTypeConverter<bool>(), &cppResult);
        }
    }

    if (PyErr_Occurred() || !pyResult) {
        Py_XDECREF(pyResult);
        return {};
    }
    return pyResult;

    Sbk_QThreadPoolFunc_waitForDone_TypeError:
        Shiboken::setErrorAboutWrongArguments(args, fullName, errInfo);
        return {};
}


static const char *Sbk_QThreadPool_PropertyStrings[] = {
    "activeThreadCount:",
    "expiryTimeout::",
    "maxThreadCount::",
    "stackSize::",
    "threadPriority::",
    nullptr // Sentinel
};

static PyMethodDef Sbk_QThreadPool_methods[] = {
    {"activeThreadCount", reinterpret_cast<PyCFunction>(Sbk_QThreadPoolFunc_activeThreadCount), METH_NOARGS},
    {"clear", reinterpret_cast<PyCFunction>(Sbk_QThreadPoolFunc_clear), METH_NOARGS},
    {"contains", reinterpret_cast<PyCFunction>(Sbk_QThreadPoolFunc_contains), METH_O},
    {"expiryTimeout", reinterpret_cast<PyCFunction>(Sbk_QThreadPoolFunc_expiryTimeout), METH_NOARGS},
    {"globalInstance", reinterpret_cast<PyCFunction>(Sbk_QThreadPoolFunc_globalInstance), METH_NOARGS|METH_STATIC},
    {"maxThreadCount", reinterpret_cast<PyCFunction>(Sbk_QThreadPoolFunc_maxThreadCount), METH_NOARGS},
    {"releaseThread", reinterpret_cast<PyCFunction>(Sbk_QThreadPoolFunc_releaseThread), METH_NOARGS},
    {"reserveThread", reinterpret_cast<PyCFunction>(Sbk_QThreadPoolFunc_reserveThread), METH_NOARGS},
    {"setExpiryTimeout", reinterpret_cast<PyCFunction>(Sbk_QThreadPoolFunc_setExpiryTimeout), METH_O},
    {"setMaxThreadCount", reinterpret_cast<PyCFunction>(Sbk_QThreadPoolFunc_setMaxThreadCount), METH_O},
    {"setStackSize", reinterpret_cast<PyCFunction>(Sbk_QThreadPoolFunc_setStackSize), METH_O},
    {"setThreadPriority", reinterpret_cast<PyCFunction>(Sbk_QThreadPoolFunc_setThreadPriority), METH_O},
    {"stackSize", reinterpret_cast<PyCFunction>(Sbk_QThreadPoolFunc_stackSize), METH_NOARGS},
    {"start", reinterpret_cast<PyCFunction>(Sbk_QThreadPoolFunc_start), METH_VARARGS|METH_KEYWORDS},
    {"threadPriority", reinterpret_cast<PyCFunction>(Sbk_QThreadPoolFunc_threadPriority), METH_NOARGS},
    {"tryStart", reinterpret_cast<PyCFunction>(Sbk_QThreadPoolFunc_tryStart), METH_O},
    {"tryTake", reinterpret_cast<PyCFunction>(Sbk_QThreadPoolFunc_tryTake), METH_O},
    {"waitForDone", reinterpret_cast<PyCFunction>(Sbk_QThreadPoolFunc_waitForDone), METH_VARARGS|METH_KEYWORDS},

    {nullptr, nullptr} // Sentinel
};

static int Sbk_QThreadPool_setattro(PyObject *self, PyObject *name, PyObject *value)
{
    PySide::Feature::Select(self);
    if (value && PyCallable_Check(value)) {
        auto plain_inst = reinterpret_cast< ::QThreadPool *>(Shiboken::Conversions::cppPointer(SbkPySide6_QtCoreTypes[SBK_QTHREADPOOL_IDX], reinterpret_cast<SbkObject *>(self)));
        auto inst = dynamic_cast<QThreadPoolWrapper *>(plain_inst);
        if (inst)
            inst->resetPyMethodCache();
    }
    Shiboken::AutoDecRef pp(reinterpret_cast<PyObject *>(PySide::Property::getObject(self, name)));
    if (!pp.isNull())
        return PySide::Property::setValue(reinterpret_cast<PySideProperty *>(pp.object()), self, value);
    return PyObject_GenericSetAttr(self, name, value);
}

} // extern "C"

static int Sbk_QThreadPool_traverse(PyObject *self, visitproc visit, void *arg)
{
    return SbkObject_TypeF()->tp_traverse(self, visit, arg);
}
static int Sbk_QThreadPool_clear(PyObject *self)
{
    return reinterpret_cast<PyTypeObject *>(SbkObject_TypeF())->tp_clear(self);
}
// Class Definition -----------------------------------------------
extern "C" {
static PyTypeObject *_Sbk_QThreadPool_Type = nullptr;
static PyTypeObject *Sbk_QThreadPool_TypeF(void)
{
    return _Sbk_QThreadPool_Type;
}

static PyType_Slot Sbk_QThreadPool_slots[] = {
    {Py_tp_base,        nullptr}, // inserted by introduceWrapperType
    {Py_tp_dealloc,     reinterpret_cast<void *>(&SbkDeallocWrapper)},
    {Py_tp_repr,        nullptr},
    {Py_tp_hash,        nullptr},
    {Py_tp_call,        nullptr},
    {Py_tp_str,         nullptr},
    {Py_tp_getattro,    nullptr},
    {Py_tp_setattro,    reinterpret_cast<void *>(Sbk_QThreadPool_setattro)},
    {Py_tp_traverse,    reinterpret_cast<void *>(Sbk_QThreadPool_traverse)},
    {Py_tp_clear,       reinterpret_cast<void *>(Sbk_QThreadPool_clear)},
    {Py_tp_richcompare, nullptr},
    {Py_tp_iter,        nullptr},
    {Py_tp_iternext,    nullptr},
    {Py_tp_methods,     reinterpret_cast<void *>(Sbk_QThreadPool_methods)},
    {Py_tp_getset,      nullptr},
    {Py_tp_init,        reinterpret_cast<void *>(Sbk_QThreadPool_Init)},
    {Py_tp_new,         reinterpret_cast<void *>(SbkObjectTpNew)},
    {0, nullptr}
};
static PyType_Spec Sbk_QThreadPool_spec = {
    "2:PySide6.QtCore.QThreadPool",
    sizeof(SbkObject),
    0,
    Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC,
    Sbk_QThreadPool_slots
};

} //extern "C"

static void *Sbk_QThreadPool_typeDiscovery(void *cptr, PyTypeObject *instanceType)
{
    if (instanceType == Shiboken::SbkType< ::QObject >())
        return dynamic_cast< ::QThreadPool *>(reinterpret_cast< ::QObject *>(cptr));
    return {};
}


// Type conversion functions.

// Python to C++ pointer conversion - returns the C++ object of the Python wrapper (keeps object identity).
static void QThreadPool_PythonToCpp_QThreadPool_PTR(PyObject *pyIn, void *cppOut)
{
    Shiboken::Conversions::pythonToCppPointer(Sbk_QThreadPool_TypeF(), pyIn, cppOut);
}
static PythonToCppFunc is_QThreadPool_PythonToCpp_QThreadPool_PTR_Convertible(PyObject *pyIn)
{
    if (pyIn == Py_None)
        return Shiboken::Conversions::nonePythonToCppNullPtr;
    if (PyObject_TypeCheck(pyIn, reinterpret_cast<PyTypeObject *>(Sbk_QThreadPool_TypeF())))
        return QThreadPool_PythonToCpp_QThreadPool_PTR;
    return {};
}

// C++ to Python pointer conversion - tries to find the Python wrapper for the C++ object (keeps object identity).
static PyObject *QThreadPool_PTR_CppToPython_QThreadPool(const void *cppIn)
{
    return PySide::getWrapperForQObject(reinterpret_cast<::QThreadPool *>(const_cast<void *>(cppIn)), Sbk_QThreadPool_TypeF());

}

// The signatures string for the functions.
// Multiple signatures have their index "n:" in front.
static const char *QThreadPool_SignatureStrings[] = {
    "PySide6.QtCore.QThreadPool(self,parent:PySide6.QtCore.QObject=nullptr)",
    "PySide6.QtCore.QThreadPool.activeThreadCount(self)->int",
    "PySide6.QtCore.QThreadPool.clear(self)",
    "PySide6.QtCore.QThreadPool.contains(self,thread:PySide6.QtCore.QThread)->bool",
    "PySide6.QtCore.QThreadPool.expiryTimeout(self)->int",
    "PySide6.QtCore.QThreadPool.globalInstance()->PySide6.QtCore.QThreadPool",
    "PySide6.QtCore.QThreadPool.maxThreadCount(self)->int",
    "PySide6.QtCore.QThreadPool.releaseThread(self)",
    "PySide6.QtCore.QThreadPool.reserveThread(self)",
    "PySide6.QtCore.QThreadPool.setExpiryTimeout(self,expiryTimeout:int)",
    "PySide6.QtCore.QThreadPool.setMaxThreadCount(self,maxThreadCount:int)",
    "PySide6.QtCore.QThreadPool.setStackSize(self,stackSize:uint)",
    "PySide6.QtCore.QThreadPool.setThreadPriority(self,priority:PySide6.QtCore.QThread.Priority)",
    "PySide6.QtCore.QThreadPool.stackSize(self)->uint",
    "1:PySide6.QtCore.QThreadPool.start(self,arg__1:PyCallable,priority:int=0)",
    "0:PySide6.QtCore.QThreadPool.start(self,runnable:PySide6.QtCore.QRunnable,priority:int=0)",
    "PySide6.QtCore.QThreadPool.threadPriority(self)->PySide6.QtCore.QThread.Priority",
    "1:PySide6.QtCore.QThreadPool.tryStart(self,arg__1:PyCallable)->bool",
    "0:PySide6.QtCore.QThreadPool.tryStart(self,runnable:PySide6.QtCore.QRunnable)->bool",
    "PySide6.QtCore.QThreadPool.tryTake(self,runnable:PySide6.QtCore.QRunnable)->bool",
    "PySide6.QtCore.QThreadPool.waitForDone(self,msecs:int=-1)->bool",
    nullptr}; // Sentinel

void init_QThreadPool(PyObject *module)
{
    _Sbk_QThreadPool_Type = Shiboken::ObjectType::introduceWrapperType(
        module,
        "QThreadPool",
        "QThreadPool*",
        &Sbk_QThreadPool_spec,
        &Shiboken::callCppDestructor< ::QThreadPool >,
        SbkPySide6_QtCoreTypes[SBK_QOBJECT_IDX],
        0,
        0);
    auto *pyType = Sbk_QThreadPool_TypeF(); // references _Sbk_QThreadPool_Type
    InitSignatureStrings(pyType, QThreadPool_SignatureStrings);
    SbkObjectType_SetPropertyStrings(reinterpret_cast<PyTypeObject *>(_Sbk_QThreadPool_Type), Sbk_QThreadPool_PropertyStrings);
    SbkPySide6_QtCoreTypes[SBK_QTHREADPOOL_IDX]
        = Sbk_QThreadPool_TypeF();

    // Register Converter
    SbkConverter *converter = Shiboken::Conversions::createConverter(Sbk_QThreadPool_TypeF(),
        QThreadPool_PythonToCpp_QThreadPool_PTR,
        is_QThreadPool_PythonToCpp_QThreadPool_PTR_Convertible,
        QThreadPool_PTR_CppToPython_QThreadPool);

    Shiboken::Conversions::registerConverterName(converter, "QThreadPool");
    Shiboken::Conversions::registerConverterName(converter, "QThreadPool*");
    Shiboken::Conversions::registerConverterName(converter, "QThreadPool&");
    Shiboken::Conversions::registerConverterName(converter, typeid(::QThreadPool).name());
    Shiboken::Conversions::registerConverterName(converter, typeid(::QThreadPoolWrapper).name());


    Shiboken::ObjectType::setTypeDiscoveryFunctionV2(Sbk_QThreadPool_TypeF(), &Sbk_QThreadPool_typeDiscovery);

    PySide::Signal::registerSignals(Sbk_QThreadPool_TypeF(), &::QThreadPool::staticMetaObject);
    Shiboken::ObjectType::setSubTypeInitHook(Sbk_QThreadPool_TypeF(), &PySide::initQObjectSubType);
    PySide::initDynamicMetaObject(Sbk_QThreadPool_TypeF(), &::QThreadPool::staticMetaObject, sizeof(QThreadPoolWrapper));
}
