File: qobject.sip

package info (click to toggle)
python-qt4 4.0.1-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 18,632 kB
  • ctags: 2,639
  • sloc: python: 29,409; sh: 5,646; cpp: 3,168; xml: 149; makefile: 109
file content (1523 lines) | stat: -rw-r--r-- 42,530 bytes parent folder | download
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
// qobject.sip generated by MetaSIP on Sat Jul 15 18:43:36 2006
//
// This file is part of the QtCore Python extension module.
//
// Copyright (c) 2006
// 	Riverbank Computing Limited <info@riverbankcomputing.co.uk>
// 
// This file is part of PyQt.
// 
// This copy of PyQt is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2, or (at your option) any later
// version.
// 
// PyQt is supplied in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
// details.
// 
// You should have received a copy of the GNU General Public License along with
// PyQt; see the file LICENSE.  If not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


class QWidget /External/;
typedef QList<QObject*> QObjectList;

class QObject
{
%TypeHeaderCode
#include <qobject.h>
%End

%TypeCode
// This is needed by the tr() and trUt8() handwritten implementations.
#include <qcoreapplication.h>


// These are the recursive helper functions for QObject::findChild() and
// QObject::findChildren.

static PyObject *qtcore_FindChild(const QObject *parent, PyTypeObject *type, const QString &name)
{
    const QObjectList &children = parent->children();
    int i;

    for (i = 0; i < children.size(); ++i)
    {
        QObject *obj = children.at(i);

        // Skip if the name doesn't match.
        if (!name.isNull() && obj->objectName() != name)
            continue;

        PyObject *pyo = sipConvertFromInstance(obj, sipClass_QObject, 0);

        if (!pyo || PyType_IsSubtype(pyo->ob_type, type))
            return pyo;

        Py_DECREF(pyo);
    }

    for (i = 0; i < children.size(); ++i)
    {
        PyObject *pyo = qtcore_FindChild(children.at(i), type, name);

        if (pyo != Py_None)
            return pyo;

        Py_DECREF(pyo);
    }

    Py_INCREF(Py_None);
    return Py_None;
}

static int qtcore_FindChildren(const QObject *parent, PyTypeObject *type, const QString &name, PyObject *list)
{
    const QObjectList &children = parent->children();
    int i;

    for (i = 0; i < children.size(); ++i)
    {
        QObject *obj = children.at(i);

        // Skip if the name doesn't match.
        if (!name.isNull() && obj->objectName() != name)
            continue;

        PyObject *pyo = sipConvertFromInstance(obj, sipClass_QObject, 0);

        if (!pyo)
            return -1;

        if (PyType_IsSubtype(pyo->ob_type, type))
            if (PyList_Append(list, pyo) < 0)
            {
                Py_DECREF(pyo);
                return -1;
            }

        Py_DECREF(pyo);

        if (qtcore_FindChildren(obj, type, name, list) < 0)
            return -1;
    }

    return 0;
}

static int qtcore_FindChildren(const QObject *parent, PyTypeObject *type, const QRegExp &re, PyObject *list)
{
    const QObjectList &children = parent->children();
    int i;

    for (i = 0; i < children.size(); ++i)
    {
        QObject *obj = children.at(i);

        // Skip if the name doesn't match.
        if (re.indexIn(obj->objectName()) == -1)
            continue;

        PyObject *pyo = sipConvertFromInstance(obj, sipClass_QObject, 0);

        if (!pyo)
            return -1;

        if (PyType_IsSubtype(pyo->ob_type, type))
            if (PyList_Append(list, pyo) < 0)
            {
                Py_DECREF(pyo);
                return -1;
            }

        Py_DECREF(pyo);

        if (qtcore_FindChildren(obj, type, re, list) < 0)
            return -1;
    }

    return 0;
}
%End

%ConvertToSubClassCode
    static struct class_graph {
        char *name;
        sipWrapperType **type;
        int yes, no;
    } graph[] = {
        {sipName_QAbstractEventDispatcher, &sipClass_QAbstractEventDispatcher, -1, 1},
        {sipName_QEventLoop,               &sipClass_QEventLoop,               -1, 2},
        {sipName_QPluginLoader,            &sipClass_QPluginLoader,            -1, 3},
        {sipName_QSocketNotifier,          &sipClass_QSocketNotifier,          -1, 4},
        {sipName_QLibrary,                 &sipClass_QLibrary,                 -1, 5},
        {sipName_QTranslator,              &sipClass_QTranslator,              -1, 6},
        {sipName_QCoreApplication,         &sipClass_QCoreApplication,         -1, 7},
        {sipName_QSettings,                &sipClass_QSettings,                -1, 8},
        {sipName_QSignalMapper,            &sipClass_QSignalMapper,            -1, 9},
        {sipName_QIODevice,                &sipClass_QIODevice,                15, 10},
        {sipName_QAbstractItemModel,       &sipClass_QAbstractItemModel,       19, 11},
        {sipName_QObjectCleanupHandler,    &sipClass_QObjectCleanupHandler,    -1, 12},
        {sipName_QTimer,                   &sipClass_QTimer,                   -1, 13},
        {sipName_QThread,                  &sipClass_QThread,                  -1, 14},
        {sipName_QMimeData,                &sipClass_QMimeData,                -1, -1},
        {sipName_QFile,                    &sipClass_QFile,                    18, 16},
        {sipName_QProcess,                 &sipClass_QProcess,                 -1, 17},
        {sipName_QBuffer,                  &sipClass_QBuffer,                  -1, -1},
        {sipName_QTemporaryFile,           &sipClass_QTemporaryFile,           -1, -1},
        {sipName_QAbstractTableModel,      &sipClass_QAbstractTableModel,      -1, 20},
        {sipName_QAbstractListModel,       &sipClass_QAbstractListModel,       -1, -1},
    };
    
    int i = 0;
    
    sipClass = NULL;
    
    do
    {
        struct class_graph *cg = &graph[i];
    
        if (cg->name != NULL && sipCpp->inherits(cg->name))
        {
            sipClass = *cg->type;
            i = cg->yes;
        }
        else
            i = cg->no;
    }
    while (i >= 0);
%End

public:
    explicit QObject(QObject *parent /TransferThis/ = 0);
    virtual ~QObject();
    virtual bool event(QEvent *);
    virtual bool eventFilter(QObject *, QEvent *);
    QString tr(const char *, const char * = 0) const;
%MethodCode
        // Note that tr() is really a static method.  We pretend it isn't so we can use
        // self to get hold of the class name.
        
        PyObject *nmobj = sipClassName(sipSelf);
        
        if (nmobj)
        {
            char *cname = PyString_AsString(nmobj);
        
            if (cname && QCoreApplication::instance())
                sipRes = new QString(QCoreApplication::instance()->translate(cname, a0, a1, QCoreApplication::DefaultCodec));
            else
                sipRes = new QString(QString::fromLatin1(a0));
        
            Py_DECREF(nmobj);
        }
        else
            sipIsErr = 1;
%End

    QString trUtf8(const char *, const char * = 0) const;
%MethodCode
        // Note that trUtf8() is really a static method.  We pretend it isn't aren't so
        // we can use self to get hold of the class name.
        
        PyObject *nmobj = sipClassName(sipSelf);
        
        if (nmobj)
        {
            char *cname = PyString_AsString(nmobj);
        
            if (cname && QCoreApplication::instance())
                sipRes = new QString(QCoreApplication::instance()->translate(cname, a0, a1, QCoreApplication::UnicodeUTF8));
            else
                sipRes = new QString(QString::fromUtf8(a0));
        
            Py_DECREF(nmobj);
        }
        else
            sipIsErr = 1;
%End

    const QMetaObject *metaObject() const;
%MethodCode
        // We do this for historical reasons when SIP didn't distinguish between bound
        // and unbound calls and this allowed us to get the meta-object of unwrapped
        // classes (eg. plugins).  These days we could use the SIP generated code (and
        // not disable it in every QObject sub-class).  We'll leave it for the moment
        // until related issues have been sorted out (eg. Qt Designer custom widgets).
        sipRes = sipCpp->metaObject();
%End

    SIP_PYOBJECT findChild(SIP_PYTYPE type, const QString &name = QString()) const;
%MethodCode
        sipRes = qtcore_FindChild(sipCpp, (PyTypeObject *)a0, *a1);
        
        if (!sipRes)
            sipIsErr = 1;
%End

    SIP_PYLIST findChildren(SIP_PYTYPE type, const QString &name = QString()) const;
%MethodCode
        if ((sipRes = PyList_New(0)) == NULL || qtcore_FindChildren(sipCpp, (PyTypeObject *)a0, *a1, sipRes) < 0)
        {
            Py_XDECREF(sipRes);
            sipIsErr = 1;
        }
%End

    SIP_PYLIST findChildren(SIP_PYTYPE type, const QRegExp &regExp) const;
%MethodCode
        if ((sipRes = PyList_New(0)) == NULL || qtcore_FindChildren(sipCpp, (PyTypeObject *)a0, *a1, sipRes) < 0)
        {
            Py_XDECREF(sipRes);
            sipIsErr = 1;
        }
%End

    void emit(SIP_SIGNAL, ...) const;
%MethodCode
        if (sipEmitSignal(sipSelf, a0, a1) < 0)
            sipIsErr = 1;
%End

    QString objectName() const;
    void setObjectName(const QString &name);
    bool isWidgetType() const;
    bool signalsBlocked() const;
    bool blockSignals(bool b);
    QThread *thread() const;
    void moveToThread(QThread *thread);
    int startTimer(int interval);
    void killTimer(int id);
    const QObjectList &children() const;
    void setParent(QObject * /TransferThis/);
    void installEventFilter(QObject *);
    void removeEventFilter(QObject *);
    static SIP_PYOBJECT connect(SIP_QOBJECT, SIP_SIGNAL, SIP_QOBJECT, SIP_SLOT, Qt::ConnectionType=Qt::AutoConnection);
%MethodCode
        sipRes = sipConnectRx(a0, a1, a2, a3, (int)a4);
%End

    static SIP_PYOBJECT connect(SIP_QOBJECT, SIP_SIGNAL, SIP_PYCALLABLE, Qt::ConnectionType=Qt::AutoConnection);
%MethodCode
        sipRes = sipConnectRx(a0, a1, a2, 0, (int)a3);
%End

    SIP_PYOBJECT connect(SIP_QOBJECT, SIP_SIGNAL, SIP_SLOT, Qt::ConnectionType=Qt::AutoConnection) const;
%MethodCode
        sipRes = sipConnectRx(a0, a1, sipSelf, a2, (int)a3);
%End

    static SIP_PYOBJECT disconnect(SIP_QOBJECT, SIP_SIGNAL, SIP_QOBJECT, SIP_SLOT);
%MethodCode
        sipRes = sipDisconnectRx(a0, a1, a2, a3);
%End

    static SIP_PYOBJECT disconnect(SIP_QOBJECT, SIP_SIGNAL, SIP_PYCALLABLE);
%MethodCode
        sipRes = sipDisconnectRx(a0, a1, a2, 0);
%End

    void dumpObjectTree();
    void dumpObjectInfo();
    bool setProperty(const char *name, const QVariant &value);
    QVariant property(const char *name) const;

signals:
    void destroyed(QObject * = 0);

public:
    QObject *parent() const;
    bool inherits(const char *classname) const;
%MethodCode
        // The Qt implementation doesn't know anything about Python sub-classes so we
        // use the Python type's MRO.
        
        PyObject *mro = sipSelf->ob_type->tp_mro;
        
        sipRes = 0;
        
        for (int i = 0; i < PyTuple_GET_SIZE(mro); ++i)
            if (strcmp(((PyTypeObject *)PyTuple_GET_ITEM(mro, i))->tp_name, a0) == 0)
            {
                sipRes = 1;
                break;
            }
%End

public slots:
    void deleteLater();

protected:
    SIP_PYOBJECT sender() const [QObject * ()];
%MethodCode
        // This is actually protected but we never need to call the real method.
        
        sipRes = sipGetSender();
%End

    int receivers(SIP_SIGNAL signal) const;
%MethodCode
        // We also need to take into account any proxies for Python signals.
        sipRes = sipCpp->sipProtect_receivers(a0);
        
        const QObjectList &children = sipCpp->children();
        
        // Import the helper if it hasn't already been done.
        typedef int (*helper_func)(const QObject *, const char *);
        
        static helper_func helper = 0;
        
        if (!helper)
            helper = (helper_func)sipImportSymbol("qtcore_receivers");
        
        if (helper)
            for (int i = 0; i < children.size(); ++i)
                sipRes += helper(children[i], a0);
%End

    virtual void timerEvent(QTimerEvent *);
    virtual void childEvent(QChildEvent *);
    virtual void customEvent(QEvent *);
    virtual void connectNotify(SIP_SIGNAL signal);
    virtual void disconnectNotify(SIP_SIGNAL signal);

private:
    QObject(const QObject &);
};

SIP_PYOBJECT QT_TR_NOOP(SIP_PYOBJECT);
%MethodCode
    Py_INCREF(a0);
    sipRes = a0;
%End

SIP_PYOBJECT QT_TRANSLATE_NOOP(SIP_PYOBJECT, SIP_PYOBJECT);
%MethodCode
    Py_INCREF(a1);
    sipRes = a1;
%End

SIP_PYOBJECT SLOT(const char *);
%MethodCode
    if (!a0)
    {
        PyErr_Format(PyExc_TypeError, "QtCore.SLOT() slot name cannot be None");
        sipIsErr = 1;
    }
    else
    {
        QByteArray ns = QMetaObject::normalizedSignature(a0);
    
        if ((sipRes = PyString_FromStringAndSize(NULL, 1 + ns.size())) == NULL)
            sipIsErr = 1;
        else
        {
            char *dp = PyString_AS_STRING(sipRes);
    
            *dp++ = '1';
    
            qstrcpy(dp, ns.constData());
        }
    }
%End

SIP_PYOBJECT SIGNAL(const char *);
%MethodCode
    if (!a0)
    {
        PyErr_Format(PyExc_TypeError, "QtCore.SIGNAL() signal cannot be None");
        sipIsErr = 1;
    }
    else
    {
        QByteArray ns = QMetaObject::normalizedSignature(a0);
    
        if ((sipRes = PyString_FromStringAndSize(NULL, 1 + ns.size())) == NULL)
            sipIsErr = 1;
        else
        {
            char *dp = PyString_AS_STRING(sipRes);
    
            *dp++ = '2';
    
            qstrcpy(dp, ns.constData());
        }
    }
%End

SIP_PYOBJECT pyqtSignature(const char *);
%MethodCode
    // Normalise the signature and convert it back to a Python string object.
    PyObject *sig = PyString_FromString(QMetaObject::normalizedSignature(a0));
    
    if (sig)
    {
        // Create the decorator function itself.  We stash the signature in "self".
        // This may be an abuse, but it seems to be Ok.
        static PyMethodDef decorator = {
            (char *)"_deco", qtcore_decorator, METH_O, NULL
        };
    
        sipRes = PyCFunction_New(&decorator, sig);
    
        Py_DECREF(sig);
    }
%End

%ModuleCode
// This is the Qt support code for SIP.

#include <qobject.h>
#include <qmetaobject.h>
#include <qmutex.h>


// This class is used as a signal on behalf of Python signals and as a slot on
// behalf of Python callables.  It is derived from QObject but is not run
// through moc.  Instead the normal moc-generated methods are handwritten in
// order to implement a universal signal or slot.  This requires some knowledge
// of the internal implementation of signals and slots but it is likely that
// they will only change between major Qt versions.
class PyQtProxy : public QObject
{
public:
    PyQtProxy(QObject *parent, const char *pysig);
    PyQtProxy(QObject *parent, const sipSignature *psig);
    PyQtProxy(QObject *qtx, sipSlotConnection *conn, const char **member);
    ~PyQtProxy();

    static const QMetaObject staticMetaObject;
    virtual const QMetaObject *metaObject() const;
    virtual void *qt_metacast(const char *);
    virtual int qt_metacall(QMetaObject::Call, int, void **);

    void pysignal(PyObject *pyargs);
    void unislot(void **qargs);

    int getReceivers(const char *signal) const;

    static const QObject *lastSender;

    static QMutex mutex;
    static PyQtProxy *uniproxies;
    PyQtProxy *nextup, *prevup;

    const sipSignature *sig_sig;
    char *pysig_name;
    sipSlotConnection slot_conn;
    bool is_slot;

private:
    void init();

    QMetaObject *sigmo;

    PyQtProxy(const PyQtProxy &);
    PyQtProxy &operator=(const PyQtProxy &);
};


static const uint slot_meta_data[] = {
    // content:
    1,       // revision
    0,       // classname
    0,    0, // classinfo
    2,   10, // methods (number, offset in this array of first one)
    0,    0, // properties
    0,    0, // enums/sets

    // signals: signature, parameters, type, tag, flags
    11,   10,   10,   10, 0x05,

    // slots: signature, parameters, type, tag, flags
    31,   10,   10,   10, 0x0a,

    0        // eod
};


static const char slot_meta_stringdata[] = {
    "PyQtProxy\0\0pysignal(PyObject*)\0unislot()\0"
};


const QMetaObject PyQtProxy::staticMetaObject = {
    {
        &QObject::staticMetaObject,
        slot_meta_stringdata,
        slot_meta_data,
        0
    }
};


// Create a universal proxy used as a shortcut signal.
PyQtProxy::PyQtProxy(QObject *parent, const char *pysig) : QObject(parent), sig_sig(0), is_slot(false), sigmo(0)
{
    // Save the Python signal name.
    pysig_name = new char[qstrlen(pysig) + 1];
    qstrcpy(pysig_name, pysig);

    init();
}


// Create a universal proxy used as a signal.
PyQtProxy::PyQtProxy(QObject *parent, const sipSignature *psig) : QObject(parent), sig_sig(psig), pysig_name(0), is_slot(false)
{
    // Create a new meta-object on the heap so that it looks like it has a
    // signal of the right name and signature.
    sigmo = new QMetaObject;
    sigmo->d.superdata = &QObject::staticMetaObject;
    sigmo->d.extradata = 0;

    // Calculate the size of the string meta-data as follows:
    // - "PyQtProxy" and its terminating '\0',
    // - a '\0' used for any empty string,
    // - the (non-existent) argument names (ie. use the empty string if there
    //   is less that two arguments, otherwise a comma between each argument
    //   and the terminating '\0'),
    // - the name and full signature, less the initial type character, plus the
    //   terminating '\0'.
    size_t nm_len = qstrlen(slot_meta_stringdata) + 1;
    size_t len = nm_len
               + 1
               + (psig->sg_nrargs >= 2 ? psig->sg_nrargs : 0)
               + qstrlen(psig->sg_signature);

    char *smd = new char[len];
    uint i = 0, args_pos, sig_pos;

    qstrcpy(smd, slot_meta_stringdata);
    i += nm_len;

    smd[i++] = '\0';

    if (psig->sg_nrargs >= 2)
    {
        args_pos = i;

        for (int c = 1; c < psig->sg_nrargs; ++c)
            smd[i++] = ',';

        smd[i++] = '\0';
    }
    else
        args_pos = nm_len;

    sig_pos = i;
    qstrcpy(&smd[i], &psig->sg_signature[1]);

    sigmo->d.stringdata = smd;

    // Add the non-string data.
    uint *data = new uint[16];

    for (int d = 0; d < 16; ++d)
        data[d] = staticMetaObject.d.data[d];

    // Fix the changed values;
    data[10] = sig_pos;
    data[11] = args_pos;
    data[14] = 0x05;

    sigmo->d.data = data;

    init();
}


// Create a universal proxy used as a slot.  Note that this will leak if there
// is no signal transmitter (ie. no parent) - QTimer.singleShot() for example.
PyQtProxy::PyQtProxy(QObject *qtx, sipSlotConnection *connection, const char **member) : QObject(), sig_sig(0), pysig_name(0), is_slot(true), sigmo(0)
{
    // Save the connection.
    slot_conn = *connection;

    // Return the slot to connect to.
    *member = SLOT(unislot());

    init();

    // Detect when the transmitter is destroyed.
    if (qtx)
        connect(qtx, SIGNAL(destroyed(QObject *)), SLOT(deleteLater()));
}


// Initialisation common to all ctors.
void PyQtProxy::init()
{
    // Add this one to the global list.
    mutex.lock();

    nextup = uniproxies;

    if (nextup)
        nextup->prevup = this;

    prevup = 0;
    uniproxies = this;

    mutex.unlock();
}


// Destroy a universal proxy.
PyQtProxy::~PyQtProxy()
{
    if (is_slot)
        sipFreeConnection(&slot_conn);

    if (pysig_name)
        delete[] pysig_name;

    if (sigmo)
    {
        // The casts are needed for MSVC 6.
        delete[] const_cast<char *>(sigmo->d.stringdata);
        delete[] const_cast<uint *>(sigmo->d.data);
        delete sigmo;
    }

    // Remove this one from the global list.
    mutex.lock();

    if (nextup)
        nextup->prevup = prevup;

    if (prevup)
        prevup->nextup = nextup;
    else
        uniproxies = nextup;

    mutex.unlock();
}


const QObject *PyQtProxy::lastSender = 0;
QMutex PyQtProxy::mutex(QMutex::Recursive);
PyQtProxy *PyQtProxy::uniproxies = 0;


const QMetaObject *PyQtProxy::metaObject() const
{
    if (sigmo)
        return sigmo;

    return &staticMetaObject;
}


void *PyQtProxy::qt_metacast(const char *_clname)
{
    if (!_clname)
        return 0;

    if (!strcmp(_clname, slot_meta_stringdata))
        return static_cast<void *>(const_cast<PyQtProxy *>(this));

    return QObject::qt_metacast(_clname);
}


int PyQtProxy::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);

    if (_id < 0)
        return _id;

    if (_c == QMetaObject::InvokeMetaMethod)
    {
        switch (_id)
        {
        case 0:
            if (sigmo)
                QMetaObject::activate(this, sigmo, 0, _a);
            else if (sender()->metaObject() == &staticMetaObject)
                pysignal(*reinterpret_cast<PyObject **>(_a[1]));
            break;

        case 1:
            unislot(_a);
            break;
        }

        _id -= 2;
    }

    return _id;
}


// This is the signal that implements Python signals.  The argument is the
// tuple of Python argument objects.
void PyQtProxy::pysignal(PyObject *pyargs)
{
    void *_a[] = {0, reinterpret_cast<void *>(&pyargs)};

    QMetaObject::activate(this, &staticMetaObject, 0, _a);
}


// This is the universal slot itself that dispatches to the real slot.
void PyQtProxy::unislot(void **qargs)
{
    // Save the sender.  If it was a universal signal then the sender we want
    // to save is its parent.
    QObject *sndr = sender();

    if (qstrcmp(sndr->metaObject()->className(), "PyQtProxy") == 0)
        lastSender = sndr->parent();
    else
        lastSender = sndr;

    // See if the sender was a shortcircuited signal. */
    if (sndr->metaObject() == &staticMetaObject)
    {
        // The Python arguments will be the only argument.
        PyObject *pyargs = *reinterpret_cast<PyObject **>(qargs[1]);

        SIP_BLOCK_THREADS

        if (sipEmitToSlot(&slot_conn.sc_slot, pyargs) < 0)
            PyErr_Print();

        SIP_UNBLOCK_THREADS

        return;
    }

    bool ok = TRUE;
    const sipSignature *psig = slot_conn.sc_signature;

    SIP_BLOCK_THREADS

    PyObject *argtup = PyTuple_New(psig->sg_nrargs);

    if (!argtup)
        ok = FALSE;
    else
    {
        for (int a = 0; a < psig->sg_nrargs; ++a)
        {
            PyObject *arg;

            ++qargs;

            switch (psig->sg_args[a].atype)
            {
            case char_sat:
            case schar_sat:
            case uchar_sat:
                arg = PyString_FromStringAndSize((char *)*qargs, 1);
                break;

            case string_sat:
            case sstring_sat:
            case ustring_sat:
                arg = PyString_FromString(*(char **)*qargs);
                break;

            case short_sat:
                arg = PyInt_FromLong(*(short *)*qargs);
                break;

            case ushort_sat:
                arg = PyLong_FromUnsignedLong(*(unsigned short *)*qargs);
                break;

            case int_sat:
                arg = PyInt_FromLong(*(int *)*qargs);
                break;

            case uint_sat:
                arg = PyLong_FromUnsignedLong(*(unsigned *)*qargs);
                break;

            case long_sat:
                arg = PyLong_FromLong(*(long *)*qargs);
                break;

            case ulong_sat:
                arg = PyLong_FromUnsignedLong(*(unsigned long *)*qargs);
                break;

            case longlong_sat:
                arg = PyLong_FromLongLong(*(PY_LONG_LONG *)*qargs);
                break;

            case ulonglong_sat:
                arg = PyLong_FromUnsignedLongLong(*(unsigned PY_LONG_LONG *)*qargs);
                break;

            case float_sat:
                arg = PyFloat_FromDouble(*(float *)*qargs);
                break;

            case double_sat:
                arg = PyFloat_FromDouble(*(double *)*qargs);
                break;

            case enum_sat:
                arg = sipConvertFromNamedEnum(*(int *)*qargs, psig->sg_args[a].u.et);
                break;

            case bool_sat:
                arg = PyBool_FromLong(*(bool *)*qargs);
                break;

            case void_sat:
                arg = sipConvertFromVoidPtr(*(void **)*qargs);
                break;

            case class_sat:
                arg = sipConvertFromInstance(*qargs, psig->sg_args[a].u.wt, 0);
                break;

            case classp_sat:
                arg = sipConvertFromInstance(*(void **)*qargs, psig->sg_args[a].u.wt, 0);
                break;

            case mtype_sat:
                arg = sipConvertFromMappedType(*qargs, psig->sg_args[a].u.mt, 0);
                break;

            case mtypep_sat:
                arg = sipConvertFromMappedType(*(void **)*qargs, psig->sg_args[a].u.mt, 0);
                break;

            case qvariant_sat:
                arg = sipConvertFromInstance(*qargs, sipClass_QVariant, 0);
                break;

            case qvariantp_sat:
                arg = sipConvertFromInstance(*(void **)*qargs, sipClass_QVariant, 0);
                break;

            case pyobject_sat:
                arg = *(PyObject **)*qargs;
                break;

            default:
                arg = Py_NotImplemented;
                Py_INCREF(Py_NotImplemented);
            }

            PyTuple_SET_ITEM(argtup, a, arg);
        }

        // Dispatch to the real slot.
        if (ok && sipEmitToSlot(&slot_conn.sc_slot, argtup) < 0)
            ok = FALSE;

        Py_DECREF(argtup);
    }

    if (!ok)
        PyErr_Print();

    SIP_UNBLOCK_THREADS
}


// A thin wrapper around QObject::receivers().
int PyQtProxy::getReceivers(const char *signal) const
{
    return receivers(signal);
}


// Declare explicit C linkage.
extern "C"
{
    static int sipQtIsQtSignal(void *tx, const char *signal);
    static void *sipQtCreateUniversalSignalShortcut(void *tx,
                    const char *pysig, const char **sig);
    static void *sipQtFindUniversalSignalShortcut(void *tx, const char *pysig,
                    const char **sig);
    static void *sipQtCreateUniversalSignal(void *tx,
                    const sipSignature *psig);
    static void *sipQtFindUniversalSignal(void *tx, const sipSignature *psig);
    static int sipQtEmitSignalShortcut(void *tx, const char *sig,
                    PyObject *sigargs);
    static int sipQtEmitSignal(void *tx, const sipSignature *psig,
                    PyObject *sigargs);
    static void *sipQtCreateUniversalSlot(sipWrapper *tx,
                    sipSlotConnection *conn, const char **member);
    static void sipQtDestroyUniversalSlot(void *rx);
    static void *sipQtFindSlot(void *tx, const char *sig, PyObject *rxObj,
                    const char *slot, const char **member);
    static int sipQtConnect(void *tx, const char *sig, void *rx,
                    const char *slot, int type);
    static int sipQtDisconnect(void *tx, const char *sig, void *rx,
                    const char *slot);
    static int sipQtSignalsBlocked(void *qobj);
    static const void *sipQtGetSender();
    static void sipQtForgetSender();
    static int sipQtSameSignalSlotName(const char *s1, const char *s2);
}


// Return a non-zero value if a signal is a Qt signal.
static int sipQtIsQtSignal(void *tx, const char *signal)
{
    return (reinterpret_cast<QObject *>(tx)->metaObject()->indexOfSignal(&signal[1]) >= 0);
}


// Factory function to create a universal signal instance for a Python
// shortcircuited signal.  Returns a pointer to the instance or 0 if there was
// an error.
static void *sipQtCreateUniversalSignalShortcut(void *tx, const char *pysig, const char **sig)
{
    QObject *qtx = reinterpret_cast<QObject *>(tx);

    *sig = SIGNAL(pysignal(PyObject*));

    // Use an existing one if possible.
    for (PyQtProxy *up = PyQtProxy::uniproxies; up; up = up->nextup)
        if (up->parent() == qtx && up->pysig_name && qstrcmp(up->pysig_name, pysig) == 0)
            return up;

    return new PyQtProxy(qtx, pysig);
}


// Find an existing universal signal instance for a Python shortcircuited
// signal.  Returns a pointer to the instance or 0 there wasn't one.
static void *sipQtFindUniversalSignalShortcut(void *tx, const char *pysig, const char **sig)
{
    QObject *qtx = reinterpret_cast<QObject *>(tx);

    for (PyQtProxy *up = PyQtProxy::uniproxies; up; up = up->nextup)
        if (up->parent() == qtx && up->pysig_name && qstrcmp(up->pysig_name, pysig) == 0)
        {
            *sig = SIGNAL(pysignal(PyObject*));
            return up;
        }

    return 0;
}


// Factory function to create a universal signal instance.  Returns a pointer
// to the instance or 0 if there was an error.
static void *sipQtCreateUniversalSignal(void *tx, const sipSignature *psig)
{
    QObject *qtx = reinterpret_cast<QObject *>(tx);

    // Use an existing one if possible.
    for (PyQtProxy *up = PyQtProxy::uniproxies; up; up = up->nextup)
        if (up->parent() == qtx && up->sig_sig == psig)
            return up;

    return new PyQtProxy(qtx, psig);
}


// Find an existing universal signal instance.  Returns a pointer
// to the instance or 0 if there wasn't one.
static void *sipQtFindUniversalSignal(void *tx, const sipSignature *psig)
{
    QObject *qtx = reinterpret_cast<QObject *>(tx);

    for (PyQtProxy *up = PyQtProxy::uniproxies; up; up = up->nextup)
        if (up->parent() == qtx && up->sig_sig == psig)
            return up;

    return 0;
}


// Emit a shortcut signal for any QObject derived instance.  Returns 0 if there
// was no error.
static int sipQtEmitSignalShortcut(void *tx, const char *sig, PyObject *sigargs)
{
    QObject *qtx = reinterpret_cast<QObject *>(tx);

    // Find the universal signal shortcut.  Unfortunately we can't distinguish
    // between a Qt name with a typo and an unconnected Python signal - so we
    // just ignore the emit.
    PyQtProxy *up;

    for (up = PyQtProxy::uniproxies; up; up = up->nextup)
        if (up->parent() == qtx && up->pysig_name && qstrcmp(up->pysig_name, sig) == 0)
        {
            Py_BEGIN_ALLOW_THREADS
            up->pysignal(sigargs);
            Py_END_ALLOW_THREADS

            break;
        }

    return 0;
}


// Emit a signal for any QObject derived instance.  Returns 0 if there was no
// error.
static int sipQtEmitSignal(void *tx, const sipSignature *psig, PyObject *sigargs)
{
    QObject *qtx;
    const QMetaObject *otxmo;
    int idx;

    qtx = reinterpret_cast<QObject *>(tx);
    otxmo = qtx->metaObject();

    // If the signal doesn't exist then see if there is a proxy for it.
    if ((idx = otxmo->indexOfSignal(&psig->sg_signature[1])) < 0)
    {
        PyQtProxy *up;

        for (up = PyQtProxy::uniproxies; up; up = up->nextup)
            if (up->parent() == qtx && up->sig_sig == psig)
                break;

        // Unfortunately we can't distinguish between a Qt name with a typo and
        // an unconnected Python signal - so we just ignore the emit.
        if (!up)
            return 0;

        // Use the proxy instead.
        qtx = up;
        idx = up->metaObject()->indexOfSignal(&psig->sg_signature[1]);
    }

    // Convert the Python arguments to C++ arguments.  This mimics
    // sipParseArgs().

    void **argv = new void *[1 + psig->sg_nrargs];
    static void *none = 0;

    struct value {
        union {
            bool b;
            short sh;
            unsigned short ush;
            int i;
            unsigned ui;
            long l;
            unsigned long ul;
            PY_LONG_LONG ll;
            unsigned PY_LONG_LONG ull;
            float f;
            double d;
            void *v;
        } u;

        int state;
    };

    value *values = new value[psig->sg_nrargs];

    argv[0] = 0;

    for (int a = 0; a < psig->sg_nrargs; ++a)
    {
        void *arg = 0;
        PyObject *pyarg = PyTuple_GET_ITEM(sigargs, a);
        value *v = &values[a];

        PyErr_Clear();

        switch (psig->sg_args[a].atype)
        {
        case char_sat:
        case schar_sat:
        case uchar_sat:
            if (PyString_Check(pyarg) && PyString_GET_SIZE(pyarg) == 1)
                arg = PyString_AS_STRING(pyarg);
            break;

        case string_sat:
        case sstring_sat:
        case ustring_sat:
            if (pyarg == Py_None)
                arg = &none;
            else if (PyString_Check(pyarg))
                arg = &PyString_AS_STRING(pyarg);
            break;

        case short_sat:
            v->u.sh = PyInt_AsLong(pyarg);

            if (!PyErr_Occurred())
                arg = &v->u.sh;
            break;

        case ushort_sat:
            v->u.ush = sipLong_AsUnsignedLong(pyarg);

            if (!PyErr_Occurred())
                arg = &v->u.ush;
            break;

        case int_sat:
            v->u.i = PyInt_AsLong(pyarg);

            if (!PyErr_Occurred())
                arg = &v->u.i;
            break;

        case uint_sat:
            v->u.ui = sipLong_AsUnsignedLong(pyarg);

            if (!PyErr_Occurred())
                arg = &v->u.ui;
            break;

        case long_sat:
            v->u.l = PyLong_AsLong(pyarg);

            if (!PyErr_Occurred())
                arg = &v->u.l;
            break;

        case ulong_sat:
            v->u.ul = sipLong_AsUnsignedLong(pyarg);

            if (!PyErr_Occurred())
                arg = &v->u.ul;
            break;

        case longlong_sat:
            v->u.ll = PyLong_AsLongLong(pyarg);

            if (!PyErr_Occurred())
                arg = &v->u.ll;
            break;

        case ulonglong_sat:
            v->u.ull = PyLong_AsUnsignedLongLong(pyarg);

            if (!PyErr_Occurred())
                arg = &v->u.ull;
            break;

        case float_sat:
            v->u.f = PyFloat_AsDouble(pyarg);

            if (!PyErr_Occurred())
                arg = &v->u.f;
            break;

        case double_sat:
            v->u.d = PyFloat_AsDouble(pyarg);

            if (!PyErr_Occurred())
                arg = &v->u.d;
            break;

        case enum_sat:
            if (PyObject_TypeCheck(pyarg, psig->sg_args[a].u.et))
            {
                v->u.i = PyInt_AsLong(pyarg);
                arg = &v->u.i;
            }
            break;

        case bool_sat:
            v->u.b = PyInt_AsLong(pyarg);

            if (!PyErr_Occurred())
                arg = &v->u.b;
            break;

        case void_sat:
            v->u.v = sipConvertToVoidPtr(pyarg);

            if (!PyErr_Occurred())
                arg = &v->u.v;
            break;

        case class_sat:
            {
                int iserr = 0;

                arg = sipForceConvertToInstance(pyarg, psig->sg_args[a].u.wt, 0, SIP_NOT_NONE, &values[a].state, &iserr);

                if (iserr)
                    arg = 0;
            }
            break;

        case classp_sat:
            {
                int iserr = 0;

                v->u.v = sipForceConvertToInstance(pyarg, psig->sg_args[a].u.wt, 0, 0, &values[a].state, &iserr);

                if (!iserr)
                    arg = &v->u.v;
            }
            break;

        case mtype_sat:
            {
                int iserr = 0;

                arg = sipForceConvertToMappedType(pyarg, psig->sg_args[a].u.mt, 0, SIP_NOT_NONE, &values[a].state, &iserr);

                if (iserr)
                    arg = 0;
            }
            break;

        case mtypep_sat:
            {
                int iserr = 0;

                v->u.v = sipForceConvertToMappedType(pyarg, psig->sg_args[a].u.mt, 0, 0, &values[a].state, &iserr);

                if (!iserr)
                    arg = &v->u.v;
            }
            break;

        case qvariant_sat:
            {
                int iserr = 0;

                arg = sipForceConvertToInstance(pyarg, sipClass_QVariant, 0, SIP_NOT_NONE, &values[a].state, &iserr);

                if (iserr)
                    arg = 0;
            }
            break;

        case qvariantp_sat:
            {
                int iserr = 0;

                v->u.v = sipForceConvertToInstance(pyarg, sipClass_QVariant, 0, 0, &values[a].state, &iserr);

                if (!iserr)
                    arg = &v->u.v;
            }
            break;

        case pyobject_sat:
            v->u.v = pyarg;
            arg = &v->u.v;
            break;

        default:
            // Do nothing.
            ;
        }

        if (!arg)
        {
            PyErr_Format(PyExc_TypeError, "argument %d of signal %s.%s has an invalid type", a, otxmo->className(), &psig->sg_signature[1]);

            delete[] argv;
            delete[] values;

            return -1;
        }

        argv[1 + a] = arg;
    }

    Py_BEGIN_ALLOW_THREADS
    QMetaObject::activate(qtx, idx, idx, argv);
    Py_END_ALLOW_THREADS

    // Delete any temporary instances.
    for (int a = 0; a < psig->sg_nrargs; ++a)
    {
        value *v = &values[a];

        switch (psig->sg_args[a].atype)
        {
        case class_sat:
            sipReleaseInstance(argv[a], psig->sg_args[a].u.wt, v->state);
            break;

        case classp_sat:
            sipReleaseInstance(v->u.v, psig->sg_args[a].u.wt, v->state);
            break;

        case mtype_sat:
            sipReleaseMappedType(argv[a], psig->sg_args[a].u.mt, v->state);
            break;

        case mtypep_sat:
            sipReleaseMappedType(v->u.v, psig->sg_args[a].u.mt, v->state);
            break;

        case qvariant_sat:
            sipReleaseInstance(argv[a], sipClass_QVariant, v->state);
            break;

        case qvariantp_sat:
            sipReleaseInstance(v->u.v, sipClass_QVariant, v->state);
            break;

        default:
            ;
        }
    }

    delete[] argv;
    delete[] values;

    return 0;
}


// Factory function to create a universal slot instance.  Returns a pointer to
// the instance or 0 if there was an error.
static void *sipQtCreateUniversalSlot(sipWrapper *tx, sipSlotConnection *conn, const char **member)
{
    QObject *qtx = 0;

    // See if the transmitter is a QObject in which case we will connect to
    // it's destroyed signal so that the proxy can be destroyed at the same
    // time.  (Note that we used to do this by making the proxy a child of the
    // transmitter.  This doesn't work as expected because QWidget destroys its
    // children before emitting the destroyed signal.)
    if (tx && PyObject_TypeCheck(tx, (PyTypeObject *)sipClass_QObject))
        qtx = reinterpret_cast<QObject *>(conn->sc_transmitter);

    return new PyQtProxy(qtx, conn, member);
}


// Dispose of a receiver that might be a universal slot.
static void sipQtDestroyUniversalSlot(void *rx)
{
    PyQtProxy::mutex.lock();

    for (PyQtProxy *up = PyQtProxy::uniproxies; up; up = up->nextup)
        if (up == reinterpret_cast<QObject *>(rx) && up->is_slot)
        {
            delete up;
            break;
        }

    PyQtProxy::mutex.unlock();
}


// Search for the universal slot connected to a particular Qt signal.
static void *sipQtFindSlot(void *tx, const char *sig, PyObject *rxObj, const char *slot, const char **member)
{
    // There is no point in locking the mutex as the slot returned could be
    // deleted at any time afterwards anyway.

    for (PyQtProxy *up = PyQtProxy::uniproxies; up; up = up->nextup)
        if (up->is_slot && sipSameConnection(&up->slot_conn, tx, sig, rxObj, slot))
        {
            *member = SLOT(unislot());
            return up;
        }

    return 0;
}


// Connect a Qt signal to a Qt slot.
static int sipQtConnect(void *tx, const char *sig, void *rx, const char *slot, int type)
{
    // Unlike Qt3, Qt4 does not check that the signal and slot arguments are
    // compatible in a release build.  I think this is a bug, so we do the
    // missing check here.
#if defined(QT_NO_DEBUG)
    if (!QMetaObject::checkConnectArgs(sig, slot))
        return 0;
#endif

    return QObject::connect(reinterpret_cast<QObject *>(tx), sig,
                            reinterpret_cast<QObject *>(rx), slot,
                            (Qt::ConnectionType)type);
}


// Disconnect a Qt signal from a Qt slot.
static int sipQtDisconnect(void *tx, const char *sig, void *rx, const char *slot)
{
    return QObject::disconnect(reinterpret_cast<QObject *>(tx), sig,
                               reinterpret_cast<QObject *>(rx), slot);
}


// See if signals are currently blocked for a QObject.
static int sipQtSignalsBlocked(void *qobj)
{
    return reinterpret_cast<QObject *>(qobj)->signalsBlocked();
}


// Get the last sender for QObject::sender().
static const void *sipQtGetSender()
{
    return PyQtProxy::lastSender;
}


// Forget the last sender.
static void sipQtForgetSender()
{
    PyQtProxy::lastSender = 0;
}


// See if two signal or slot names are the same.
static int sipQtSameSignalSlotName(const char *s1, const char *s2)
{
    // Signal and slot names are always normalised so a simple string
    // comparison will do.
    return (qstrcmp(s1, s2) == 0);
}


// This is a helper for QObject.receivers() that returns the number of
// receivers for an object if it is a signal proxy.  It is exported because
// QObject::receivers() is protected.
static int qtcore_receivers(const QObject *obj, const char *signal)
{
    if (qstrcmp(obj->metaObject()->className(), "PyQtProxy") != 0)
            return 0;

    return static_cast<const PyQtProxy *>(obj)->getReceivers(signal);
}


// This is the decorator function that saves the C++ signature as a function
// attribute.
extern "C" {static PyObject *qtcore_decorator(PyObject *self, PyObject *f);}

static PyObject *qtcore_decorator(PyObject *self, PyObject *f)
{
    static PyObject *sigstr = 0;

    // Objectify the attribute name.
    if (!sigstr)
    {
        sigstr = PyString_FromString("_signature");

        if (!sigstr)
            return 0;
    }

    // Save the signature as an attribute.
    if (PyObject_SetAttr(f, sigstr, self) < 0)
        return 0;

    // Return the function.
    Py_INCREF(f);
    return f;
}
%End

%PostInitialisationCode
// Export the QObject.receivers() helper.
sipExportSymbol("qtcore_receivers", (void *)qtcore_receivers);
%End