summaryrefslogtreecommitdiffstats
path: root/PySide/QtCore/glue/qcoreapplication_init.cpp
blob: 5fcd79a3b9e3d02f8e8a9fd44f037c7db75f7c44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Global variables used to store argc and argv values
static int QCoreApplicationArgCount;
static char** QCoreApplicationArgValues;

/**
 * Called at QtCore module exit
 */
void DeleteQCoreApplicationAtExit() {
    if (QCoreApplication::instance()) {
        BindingManager::instance().invalidateWrapper(QCoreApplication::instance());
        QCoreApplication::instance()->deleteLater();
        for (int i = 0; i < QCoreApplicationArgCount; ++i)
            delete[] QCoreApplicationArgValues[i];
    }
}

int SbkQCoreApplication_Init(PyObject* self, PyObject* args, PyObject*)
{
    if (QCoreApplication::instance()) {
        PyErr_SetString(PyExc_RuntimeError, "A QCoreApplication instance already exists.");
        return -1;
    }

    int numArgs = PyTuple_GET_SIZE(args);
    if (numArgs != 1) {
        PyErr_BadArgument();
        return -1;
    }

    if (!PySequenceToArgcArgv(PyTuple_GET_ITEM(args, 0), &QCoreApplicationArgCount, &QCoreApplicationArgValues, "PySideApp")) {
        PyErr_BadArgument();
        return -1;
    }

    void* cptr = new QCoreApplication(QCoreApplicationArgCount, QCoreApplicationArgValues);
    Shiboken::setCppPointer(reinterpret_cast<SbkBaseWrapper*>(self),
                            Shiboken::SbkType<QCoreApplication>(),
                            cptr);
    SbkBaseWrapper_setValidCppObject(self, 1);
    Shiboken::BindingManager::instance().registerWrapper(reinterpret_cast<SbkBaseWrapper*>(self), cptr);

    Py_INCREF(self);
    Py_AtExit(DeleteQCoreApplicationAtExit);
    return 1;
}