/
qobject.go
2167 lines (1589 loc) · 83.4 KB
/
qobject.go
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
package qtcore
// /usr/include/qt/QtCore/qobject.h
// #include <qobject.h>
// #include <QtCore>
// header block end
// main block begin
// main block end
// use block begin
// use block end
// ext block begin
/*
#include <stdlib.h>
// extern C begin: 2
*/
// import "C"
import "unsafe"
import "reflect"
import "fmt"
import "log"
import "github.com/kitech/qt.go/qtrt"
// ext block end
// body block begin
// QObject * sender()
func (this *QObject) InheritSender(f func() unsafe.Pointer /*666*/) {
qtrt.SetAllInheritCallback(this, "sender", f)
}
// int senderSignalIndex()
func (this *QObject) InheritSenderSignalIndex(f func() int) {
qtrt.SetAllInheritCallback(this, "senderSignalIndex", f)
}
// int receivers(const char *)
func (this *QObject) InheritReceivers(f func(signal string) int) {
qtrt.SetAllInheritCallback(this, "receivers", f)
}
// bool isSignalConnected(const QMetaMethod &)
func (this *QObject) InheritIsSignalConnected(f func(signal *QMetaMethod) bool) {
qtrt.SetAllInheritCallback(this, "isSignalConnected", f)
}
// void timerEvent(QTimerEvent *)
func (this *QObject) InheritTimerEvent(f func(event *QTimerEvent /*777 QTimerEvent **/) /*void*/) {
qtrt.SetAllInheritCallback(this, "timerEvent", f)
}
// void childEvent(QChildEvent *)
func (this *QObject) InheritChildEvent(f func(event *QChildEvent /*777 QChildEvent **/) /*void*/) {
qtrt.SetAllInheritCallback(this, "childEvent", f)
}
// void customEvent(QEvent *)
func (this *QObject) InheritCustomEvent(f func(event *QEvent /*777 QEvent **/) /*void*/) {
qtrt.SetAllInheritCallback(this, "customEvent", f)
}
// void connectNotify(const QMetaMethod &)
func (this *QObject) InheritConnectNotify(f func(signal *QMetaMethod) /*void*/) {
qtrt.SetAllInheritCallback(this, "connectNotify", f)
}
// void disconnectNotify(const QMetaMethod &)
func (this *QObject) InheritDisconnectNotify(f func(signal *QMetaMethod) /*void*/) {
qtrt.SetAllInheritCallback(this, "disconnectNotify", f)
}
/*
*/
type QObject struct {
*qtrt.CObject
}
type QObject_ITF interface {
QObject_PTR() *QObject
}
func (ptr *QObject) QObject_PTR() *QObject { return ptr }
func (this *QObject) GetCthis() unsafe.Pointer {
if this == nil {
return nil
} else {
return this.Cthis
}
}
func (this *QObject) SetCthis(cthis unsafe.Pointer) {
if this.CObject == nil {
this.CObject = &qtrt.CObject{cthis}
} else {
this.CObject.Cthis = cthis
}
}
func NewQObjectFromPointer(cthis unsafe.Pointer) *QObject {
return &QObject{&qtrt.CObject{cthis}}
}
func (*QObject) NewFromPointer(cthis unsafe.Pointer) *QObject {
return NewQObjectFromPointer(cthis)
}
// /usr/include/qt/QtCore/qobject.h:119
// index:0
// Public virtual Visibility=Default Availability=Available
// [8] const QMetaObject * metaObject() const
/*
Returns a pointer to the meta-object of this object.
A meta-object contains information about a class that inherits QObject, e.g. class name, superclass name, properties, signals and slots. Every QObject subclass that contains the Q_OBJECT macro will have a meta-object.
The meta-object information is required by the signal/slot connection mechanism and the property system. The inherits() function also makes use of the meta-object.
If you have no pointer to an actual object instance but still want to access the meta-object of a class, you can use staticMetaObject.
Example:
QObject *obj = new QPushButton;
obj->metaObject()->className(); // returns "QPushButton"
QPushButton::staticMetaObject.className(); // returns "QPushButton"
See also staticMetaObject.
*/
func (this *QObject) MetaObject() *QMetaObject /*777 const QMetaObject **/ {
rv, err := qtrt.InvokeQtFunc6("_ZNK7QObject10metaObjectEv", qtrt.FFI_TYPE_POINTER, this.GetCthis())
qtrt.ErrPrint(err, rv)
return /*==*/ NewQMetaObjectFromPointer(unsafe.Pointer(uintptr(rv))) // 444
}
// /usr/include/qt/QtCore/qobject.h:124
// index:0
// Public Visibility=Default Availability=Available
// [-2] void QObject(QObject *)
/*
Constructs an object with parent object parent.
The parent of an object may be viewed as the object's owner. For instance, a dialog box is the parent of the OK and Cancel buttons it contains.
The destructor of a parent object destroys all child objects.
Setting parent to 0 constructs an object with no parent. If the object is a widget, it will become a top-level window.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
See also parent(), findChild(), and findChildren().
*/
func (*QObject) NewForInherit(parent QObject_ITF /*777 QObject **/) *QObject {
return NewQObject(parent)
}
func NewQObject(parent QObject_ITF /*777 QObject **/) *QObject {
var convArg0 unsafe.Pointer
if parent != nil && parent.QObject_PTR() != nil {
convArg0 = parent.QObject_PTR().GetCthis()
}
rv, err := qtrt.InvokeQtFunc6("_ZN7QObjectC2EPS_", qtrt.FFI_TYPE_POINTER, convArg0)
qtrt.ErrPrint(err, rv)
gothis := NewQObjectFromPointer(unsafe.Pointer(uintptr(rv)))
qtrt.SetFinalizer(gothis, DeleteQObject)
return gothis
}
// /usr/include/qt/QtCore/qobject.h:124
// index:0
// Public Visibility=Default Availability=Available
// [-2] void QObject(QObject *)
/*
Constructs an object with parent object parent.
The parent of an object may be viewed as the object's owner. For instance, a dialog box is the parent of the OK and Cancel buttons it contains.
The destructor of a parent object destroys all child objects.
Setting parent to 0 constructs an object with no parent. If the object is a widget, it will become a top-level window.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
See also parent(), findChild(), and findChildren().
*/
func (*QObject) NewForInheritp() *QObject {
return NewQObjectp()
}
func NewQObjectp() *QObject {
// arg: 0, QObject *=Pointer, QObject=Record, , Invalid
var convArg0 unsafe.Pointer
rv, err := qtrt.InvokeQtFunc6("_ZN7QObjectC2EPS_", qtrt.FFI_TYPE_POINTER, convArg0)
qtrt.ErrPrint(err, rv)
gothis := NewQObjectFromPointer(unsafe.Pointer(uintptr(rv)))
qtrt.SetFinalizer(gothis, DeleteQObject)
return gothis
}
// /usr/include/qt/QtCore/qobject.h:125
// index:0
// Public virtual Visibility=Default Availability=Available
// [-2] void ~QObject()
/*
*/
func DeleteQObject(this *QObject) {
rv, err := qtrt.InvokeQtFunc6("_ZN7QObjectD2Ev", qtrt.FFI_TYPE_VOID, this.GetCthis())
qtrt.Cmemset(this.GetCthis(), 9, 16)
qtrt.ErrPrint(err, rv)
this.SetCthis(nil)
}
// /usr/include/qt/QtCore/qobject.h:127
// index:0
// Public virtual Visibility=Default Availability=Available
// [1] bool event(QEvent *)
/*
This virtual function receives events to an object and should return true if the event e was recognized and processed.
The event() function can be reimplemented to customize the behavior of an object.
Make sure you call the parent event class implementation for all the events you did not handle.
Example:
class MyClass : public QWidget
{
Q_OBJECT
public:
MyClass(QWidget *parent = 0);
~MyClass();
bool event(QEvent* ev) override
{
if (ev->type() == QEvent::PolishRequest) {
// overwrite handling of PolishRequest if any
doThings();
return true;
} else if (ev->type() == QEvent::Show) {
// complement handling of Show if any
doThings2();
QWidget::event(ev);
return true;
}
// Make sure the rest of events are handled
return QWidget::event(ev);
}
};
See also installEventFilter(), timerEvent(), QCoreApplication::sendEvent(), and QCoreApplication::postEvent().
*/
func (this *QObject) Event(event QEvent_ITF /*777 QEvent **/) bool {
var convArg0 unsafe.Pointer
if event != nil && event.QEvent_PTR() != nil {
convArg0 = event.QEvent_PTR().GetCthis()
}
rv, err := qtrt.InvokeQtFunc6("_ZN7QObject5eventEP6QEvent", qtrt.FFI_TYPE_POINTER, this.GetCthis(), convArg0)
qtrt.ErrPrint(err, rv)
return rv != 0
}
// /usr/include/qt/QtCore/qobject.h:128
// index:0
// Public virtual Visibility=Default Availability=Available
// [1] bool eventFilter(QObject *, QEvent *)
/*
Filters events if this object has been installed as an event filter for the watched object.
In your reimplementation of this function, if you want to filter the event out, i.e. stop it being handled further, return true; otherwise return false.
Example:
class MainWindow : public QMainWindow
{
public:
MainWindow();
protected:
bool eventFilter(QObject *obj, QEvent *ev) override;
private:
QTextEdit *textEdit;
};
MainWindow::MainWindow()
{
textEdit = new QTextEdit;
setCentralWidget(textEdit);
textEdit->installEventFilter(this);
}
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
if (obj == textEdit) {
if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
qDebug() << "Ate key press" << keyEvent->key();
return true;
} else {
return false;
}
} else {
// pass the event on to the parent class
return QMainWindow::eventFilter(obj, event);
}
}
Notice in the example above that unhandled events are passed to the base class's eventFilter() function, since the base class might have reimplemented eventFilter() for its own internal purposes.
Warning: If you delete the receiver object in this function, be sure to return true. Otherwise, Qt will forward the event to the deleted object and the program might crash.
See also installEventFilter().
*/
func (this *QObject) EventFilter(watched QObject_ITF /*777 QObject **/, event QEvent_ITF /*777 QEvent **/) bool {
var convArg0 unsafe.Pointer
if watched != nil && watched.QObject_PTR() != nil {
convArg0 = watched.QObject_PTR().GetCthis()
}
var convArg1 unsafe.Pointer
if event != nil && event.QEvent_PTR() != nil {
convArg1 = event.QEvent_PTR().GetCthis()
}
rv, err := qtrt.InvokeQtFunc6("_ZN7QObject11eventFilterEPS_P6QEvent", qtrt.FFI_TYPE_POINTER, this.GetCthis(), convArg0, convArg1)
qtrt.ErrPrint(err, rv)
return rv != 0
}
// /usr/include/qt/QtCore/qobject.h:139
// index:0
// Public Visibility=Default Availability=Available
// [8] QString objectName() const
/*
*/
func (this *QObject) ObjectName() string {
rv, err := qtrt.InvokeQtFunc6("_ZNK7QObject10objectNameEv", qtrt.FFI_TYPE_POINTER, this.GetCthis())
qtrt.ErrPrint(err, rv)
rv2 := /*==*/ NewQStringFromPointer(unsafe.Pointer(uintptr(rv)))
rv3 := rv2.ToUtf8().Data()
/*==*/ DeleteQString(rv2)
return rv3
}
// /usr/include/qt/QtCore/qobject.h:140
// index:0
// Public Visibility=Default Availability=Available
// [-2] void setObjectName(const QString &)
/*
*/
func (this *QObject) SetObjectName(name string) {
var tmpArg0 = NewQString5(name)
var convArg0 = tmpArg0.GetCthis()
rv, err := qtrt.InvokeQtFunc6("_ZN7QObject13setObjectNameERK7QString", qtrt.FFI_TYPE_POINTER, this.GetCthis(), convArg0)
qtrt.ErrPrint(err, rv)
}
// /usr/include/qt/QtCore/qobject.h:142
// index:0
// Public inline Visibility=Default Availability=Available
// [1] bool isWidgetType() const
/*
Returns true if the object is a widget; otherwise returns false.
Calling this function is equivalent to calling inherits("QWidget"), except that it is much faster.
*/
func (this *QObject) IsWidgetType() bool {
rv, err := qtrt.InvokeQtFunc6("_ZNK7QObject12isWidgetTypeEv", qtrt.FFI_TYPE_POINTER, this.GetCthis())
qtrt.ErrPrint(err, rv)
return rv != 0
}
// /usr/include/qt/QtCore/qobject.h:143
// index:0
// Public inline Visibility=Default Availability=Available
// [1] bool isWindowType() const
/*
Returns true if the object is a window; otherwise returns false.
Calling this function is equivalent to calling inherits("QWindow"), except that it is much faster.
*/
func (this *QObject) IsWindowType() bool {
rv, err := qtrt.InvokeQtFunc6("_ZNK7QObject12isWindowTypeEv", qtrt.FFI_TYPE_POINTER, this.GetCthis())
qtrt.ErrPrint(err, rv)
return rv != 0
}
// /usr/include/qt/QtCore/qobject.h:145
// index:0
// Public inline Visibility=Default Availability=Available
// [1] bool signalsBlocked() const
/*
Returns true if signals are blocked; otherwise returns false.
Signals are not blocked by default.
See also blockSignals() and QSignalBlocker.
*/
func (this *QObject) SignalsBlocked() bool {
rv, err := qtrt.InvokeQtFunc6("_ZNK7QObject14signalsBlockedEv", qtrt.FFI_TYPE_POINTER, this.GetCthis())
qtrt.ErrPrint(err, rv)
return rv != 0
}
// /usr/include/qt/QtCore/qobject.h:146
// index:0
// Public Visibility=Default Availability=Available
// [1] bool blockSignals(bool)
/*
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). If block is false, no such blocking will occur.
The return value is the previous value of signalsBlocked().
Note that the destroyed() signal will be emitted even if the signals for this object have been blocked.
Signals emitted while being blocked are not buffered.
See also signalsBlocked() and QSignalBlocker.
*/
func (this *QObject) BlockSignals(b bool) bool {
rv, err := qtrt.InvokeQtFunc6("_ZN7QObject12blockSignalsEb", qtrt.FFI_TYPE_POINTER, this.GetCthis(), b)
qtrt.ErrPrint(err, rv)
return rv != 0
}
// /usr/include/qt/QtCore/qobject.h:148
// index:0
// Public Visibility=Default Availability=Available
// [8] QThread * thread() const
/*
Returns the thread in which the object lives.
See also moveToThread().
*/
func (this *QObject) Thread() *QThread /*777 QThread **/ {
rv, err := qtrt.InvokeQtFunc6("_ZNK7QObject6threadEv", qtrt.FFI_TYPE_POINTER, this.GetCthis())
qtrt.ErrPrint(err, rv)
return /*==*/ NewQThreadFromPointer(unsafe.Pointer(uintptr(rv))) // 444
}
// /usr/include/qt/QtCore/qobject.h:149
// index:0
// Public Visibility=Default Availability=Available
// [-2] void moveToThread(QThread *)
/*
Changes the thread affinity for this object and its children. The object cannot be moved if it has a parent. Event processing will continue in the targetThread.
To move an object to the main thread, use QApplication::instance() to retrieve a pointer to the current application, and then use QApplication::thread() to retrieve the thread in which the application lives. For example:
myObject->moveToThread(QApplication::instance()->thread());
If targetThread is zero, all event processing for this object and its children stops.
Note that all active timers for the object will be reset. The timers are first stopped in the current thread and restarted (with the same interval) in the targetThread. As a result, constantly moving an object between threads can postpone timer events indefinitely.
A QEvent::ThreadChange event is sent to this object just before the thread affinity is changed. You can handle this event to perform any special processing. Note that any new events that are posted to this object will be handled in the targetThread.
Warning: This function is not thread-safe; the current thread must be same as the current thread affinity. In other words, this function can only "push" an object from the current thread to another thread, it cannot "pull" an object from any arbitrary thread to the current thread.
See also thread().
*/
func (this *QObject) MoveToThread(thread QThread_ITF /*777 QThread **/) {
var convArg0 unsafe.Pointer
if thread != nil && thread.QThread_PTR() != nil {
convArg0 = thread.QThread_PTR().GetCthis()
}
rv, err := qtrt.InvokeQtFunc6("_ZN7QObject12moveToThreadEP7QThread", qtrt.FFI_TYPE_POINTER, this.GetCthis(), convArg0)
qtrt.ErrPrint(err, rv)
}
// /usr/include/qt/QtCore/qobject.h:151
// index:0
// Public Visibility=Default Availability=Available
// [4] int startTimer(int, Qt::TimerType)
/*
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer.
A timer event will occur every interval milliseconds until killTimer() is called. If interval is 0, then the timer event occurs once every time there are no more window system events to process.
The virtual timerEvent() function is called with the QTimerEvent event parameter class when a timer event occurs. Reimplement this function to get timer events.
If multiple timers are running, the QTimerEvent::timerId() can be used to find out which timer was activated.
Example:
class MyObject : public QObject
{
Q_OBJECT
public:
MyObject(QObject *parent = 0);
protected:
void timerEvent(QTimerEvent *event) override;
};
MyObject::MyObject(QObject *parent)
: QObject(parent)
{
startTimer(50); // 50-millisecond timer
startTimer(1000); // 1-second timer
startTimer(60000); // 1-minute timer
using namespace std::chrono;
startTimer(milliseconds(50));
startTimer(seconds(1));
startTimer(minutes(1));
// since C++14 we can use std::chrono::duration literals, e.g.:
startTimer(100ms);
startTimer(5s);
startTimer(2min);
startTimer(1h);
}
void MyObject::timerEvent(QTimerEvent *event)
{
qDebug() << "Timer ID:" << event->timerId();
}
Note that QTimer's accuracy depends on the underlying operating system and hardware. The timerType argument allows you to customize the accuracy of the timer. See Qt::TimerType for information on the different timer types. Most platforms support an accuracy of 20 milliseconds; some provide more. If Qt is unable to deliver the requested number of timer events, it will silently discard some.
The QTimer class provides a high-level programming interface with single-shot timers and timer signals instead of events. There is also a QBasicTimer class that is more lightweight than QTimer and less clumsy than using timer IDs directly.
See also timerEvent(), killTimer(), and QTimer::singleShot().
*/
func (this *QObject) StartTimer(interval int, timerType int) int {
rv, err := qtrt.InvokeQtFunc6("_ZN7QObject10startTimerEiN2Qt9TimerTypeE", qtrt.FFI_TYPE_POINTER, this.GetCthis(), interval, timerType)
qtrt.ErrPrint(err, rv)
return qtrt.Cretval2go("int", rv).(int) // 1111
}
// /usr/include/qt/QtCore/qobject.h:151
// index:0
// Public Visibility=Default Availability=Available
// [4] int startTimer(int, Qt::TimerType)
/*
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer.
A timer event will occur every interval milliseconds until killTimer() is called. If interval is 0, then the timer event occurs once every time there are no more window system events to process.
The virtual timerEvent() function is called with the QTimerEvent event parameter class when a timer event occurs. Reimplement this function to get timer events.
If multiple timers are running, the QTimerEvent::timerId() can be used to find out which timer was activated.
Example:
class MyObject : public QObject
{
Q_OBJECT
public:
MyObject(QObject *parent = 0);
protected:
void timerEvent(QTimerEvent *event) override;
};
MyObject::MyObject(QObject *parent)
: QObject(parent)
{
startTimer(50); // 50-millisecond timer
startTimer(1000); // 1-second timer
startTimer(60000); // 1-minute timer
using namespace std::chrono;
startTimer(milliseconds(50));
startTimer(seconds(1));
startTimer(minutes(1));
// since C++14 we can use std::chrono::duration literals, e.g.:
startTimer(100ms);
startTimer(5s);
startTimer(2min);
startTimer(1h);
}
void MyObject::timerEvent(QTimerEvent *event)
{
qDebug() << "Timer ID:" << event->timerId();
}
Note that QTimer's accuracy depends on the underlying operating system and hardware. The timerType argument allows you to customize the accuracy of the timer. See Qt::TimerType for information on the different timer types. Most platforms support an accuracy of 20 milliseconds; some provide more. If Qt is unable to deliver the requested number of timer events, it will silently discard some.
The QTimer class provides a high-level programming interface with single-shot timers and timer signals instead of events. There is also a QBasicTimer class that is more lightweight than QTimer and less clumsy than using timer IDs directly.
See also timerEvent(), killTimer(), and QTimer::singleShot().
*/
func (this *QObject) StartTimerp(interval int) int {
// arg: 1, Qt::TimerType=Elaborated, Qt::TimerType=Enum, , Invalid
timerType := 0
rv, err := qtrt.InvokeQtFunc6("_ZN7QObject10startTimerEiN2Qt9TimerTypeE", qtrt.FFI_TYPE_POINTER, this.GetCthis(), interval, timerType)
qtrt.ErrPrint(err, rv)
return qtrt.Cretval2go("int", rv).(int) // 1111
}
// /usr/include/qt/QtCore/qobject.h:159
// index:0
// Public Visibility=Default Availability=Available
// [-2] void killTimer(int)
/*
Kills the timer with timer identifier, id.
The timer identifier is returned by startTimer() when a timer event is started.
See also timerEvent() and startTimer().
*/
func (this *QObject) KillTimer(id int) {
rv, err := qtrt.InvokeQtFunc6("_ZN7QObject9killTimerEi", qtrt.FFI_TYPE_POINTER, this.GetCthis(), id)
qtrt.ErrPrint(err, rv)
}
// /usr/include/qt/QtCore/qobject.h:202
// index:0
// Public inline Visibility=Default Availability=Available
// [8] const QObjectList & children() const
/*
Returns a list of child objects. The QObjectList class is defined in the <QObject> header file as the following:
typedef QList<QObject*> QObjectList;
The first child added is the first object in the list and the last child added is the last object in the list, i.e. new children are appended at the end.
Note that the list order changes when QWidget children are raised or lowered. A widget that is raised becomes the last object in the list, and a widget that is lowered becomes the first object in the list.
See also findChild(), findChildren(), parent(), and setParent().
*/
func (this *QObject) Children() *QObjectList {
rv, err := qtrt.InvokeQtFunc6("_ZNK7QObject8childrenEv", qtrt.FFI_TYPE_POINTER, this.GetCthis())
qtrt.ErrPrint(err, rv)
rv2 := /*==*/ NewQObjectListFromPointer(unsafe.Pointer(uintptr(rv))) // 4441
qtrt.SetFinalizer(rv2 /*==*/, DeleteQObjectList)
return rv2
}
// /usr/include/qt/QtCore/qobject.h:204
// index:0
// Public Visibility=Default Availability=Available
// [-2] void setParent(QObject *)
/*
Makes the object a child of parent.
See also parent() and children().
*/
func (this *QObject) SetParent(parent QObject_ITF /*777 QObject **/) {
var convArg0 unsafe.Pointer
if parent != nil && parent.QObject_PTR() != nil {
convArg0 = parent.QObject_PTR().GetCthis()
}
rv, err := qtrt.InvokeQtFunc6("_ZN7QObject9setParentEPS_", qtrt.FFI_TYPE_POINTER, this.GetCthis(), convArg0)
qtrt.ErrPrint(err, rv)
}
// /usr/include/qt/QtCore/qobject.h:205
// index:0
// Public Visibility=Default Availability=Available
// [-2] void installEventFilter(QObject *)
/*
Installs an event filter filterObj on this object. For example:
monitoredObj->installEventFilter(filterObj);
An event filter is an object that receives all events that are sent to this object. The filter can either stop the event or forward it to this object. The event filter filterObj receives events via its eventFilter() function. The eventFilter() function must return true if the event should be filtered, (i.e. stopped); otherwise it must return false.
If multiple event filters are installed on a single object, the filter that was installed last is activated first.
Here's a KeyPressEater class that eats the key presses of its monitored objects:
class KeyPressEater : public QObject
{
Q_OBJECT
...
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
};
bool KeyPressEater::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
qDebug("Ate key press %d", keyEvent->key());
return true;
} else {
// standard event processing
return QObject::eventFilter(obj, event);
}
}
And here's how to install it on two widgets:
KeyPressEater *keyPressEater = new KeyPressEater(this);
QPushButton *pushButton = new QPushButton(this);
QListView *listView = new QListView(this);
pushButton->installEventFilter(keyPressEater);
listView->installEventFilter(keyPressEater);
The QShortcut class, for example, uses this technique to intercept shortcut key presses.
Warning: If you delete the receiver object in your eventFilter() function, be sure to return true. If you return false, Qt sends the event to the deleted object and the program will crash.
Note that the filtering object must be in the same thread as this object. If filterObj is in a different thread, this function does nothing. If either filterObj or this object are moved to a different thread after calling this function, the event filter will not be called until both objects have the same thread affinity again (it is not removed).
See also removeEventFilter(), eventFilter(), and event().
*/
func (this *QObject) InstallEventFilter(filterObj QObject_ITF /*777 QObject **/) {
var convArg0 unsafe.Pointer
if filterObj != nil && filterObj.QObject_PTR() != nil {
convArg0 = filterObj.QObject_PTR().GetCthis()
}
rv, err := qtrt.InvokeQtFunc6("_ZN7QObject18installEventFilterEPS_", qtrt.FFI_TYPE_POINTER, this.GetCthis(), convArg0)
qtrt.ErrPrint(err, rv)
}
// /usr/include/qt/QtCore/qobject.h:206
// index:0
// Public Visibility=Default Availability=Available
// [-2] void removeEventFilter(QObject *)
/*
Removes an event filter object obj from this object. The request is ignored if such an event filter has not been installed.
All event filters for this object are automatically removed when this object is destroyed.
It is always safe to remove an event filter, even during event filter activation (i.e. from the eventFilter() function).
See also installEventFilter(), eventFilter(), and event().
*/
func (this *QObject) RemoveEventFilter(obj QObject_ITF /*777 QObject **/) {
var convArg0 unsafe.Pointer
if obj != nil && obj.QObject_PTR() != nil {
convArg0 = obj.QObject_PTR().GetCthis()
}
rv, err := qtrt.InvokeQtFunc6("_ZN7QObject17removeEventFilterEPS_", qtrt.FFI_TYPE_POINTER, this.GetCthis(), convArg0)
qtrt.ErrPrint(err, rv)
}
// /usr/include/qt/QtCore/qobject.h:208
// index:0
// Public static Visibility=Default Availability=Available
// [8] QMetaObject::Connection connect(const QObject *, const char *, const QObject *, const char *, Qt::ConnectionType)
/*
Creates a connection of the given type from the signal in the sender object to the method in the receiver object. Returns a handle to the connection that can be used to disconnect it later.
You must use the SIGNAL() and SLOT() macros when specifying the signal and the method, for example:
QLabel *label = new QLabel;
QScrollBar *scrollBar = new QScrollBar;
QObject::connect(scrollBar, SIGNAL(valueChanged(int)),
label, SLOT(setNum(int)));
This example ensures that the label always displays the current scroll bar value. Note that the signal and slots parameters must not contain any variable names, only the type. E.g. the following would not work and return false:
// WRONG
QObject::connect(scrollBar, SIGNAL(valueChanged(int value)),
label, SLOT(setNum(int value)));
A signal can also be connected to another signal:
class MyWidget : public QWidget
{
Q_OBJECT
public:
MyWidget();
signals:
void buttonClicked();
private:
QPushButton *myButton;
};
MyWidget::MyWidget()
{
myButton = new QPushButton(this);
connect(myButton, SIGNAL(clicked()),
this, SIGNAL(buttonClicked()));
}
In this example, the MyWidget constructor relays a signal from a private member variable, and makes it available under a name that relates to MyWidget.
A signal can be connected to many slots and signals. Many signals can be connected to one slot.
If a signal is connected to several slots, the slots are activated in the same order in which the connections were made, when the signal is emitted.
The function returns a QMetaObject::Connection that represents a handle to a connection if it successfully connects the signal to the slot. The connection handle will be invalid if it cannot create the connection, for example, if QObject is unable to verify the existence of either signal or method, or if their signatures aren't compatible. You can check if the handle is valid by casting it to a bool.
By default, a signal is emitted for every connection you make; two signals are emitted for duplicate connections. You can break all of these connections with a single disconnect() call. If you pass the Qt::UniqueConnection type, the connection will only be made if it is not a duplicate. If there is already a duplicate (exact same signal to the exact same slot on the same objects), the connection will fail and connect will return an invalid QMetaObject::Connection.
Note: Qt::UniqueConnections do not work for lambdas, non-member functions and functors; they only apply to connecting to member functions.
The optional type parameter describes the type of connection to establish. In particular, it determines whether a particular signal is delivered to a slot immediately or queued for delivery at a later time. If the signal is queued, the parameters must be of types that are known to Qt's meta-object system, because Qt needs to copy the arguments to store them in an event behind the scenes. If you try to use a queued connection and get the error message
QObject::connect: Cannot queue arguments of type 'MyType'
(Make sure 'MyType' is registered using qRegisterMetaType().)
call qRegisterMetaType() to register the data type before you establish the connection.
Note: This function is thread-safe.
See also disconnect(), sender(), qRegisterMetaType(), Q_DECLARE_METATYPE(), and Differences between String-Based and Functor-Based Connections.
*/
func (this *QObject) Connect(sender QObject_ITF /*777 const QObject **/, signal string, receiver QObject_ITF /*777 const QObject **/, member string, arg4 int) int {
var convArg0 unsafe.Pointer
if sender != nil && sender.QObject_PTR() != nil {
convArg0 = sender.QObject_PTR().GetCthis()
}
var convArg1 = qtrt.CString(signal)
defer qtrt.FreeMem(convArg1)
var convArg2 unsafe.Pointer
if receiver != nil && receiver.QObject_PTR() != nil {
convArg2 = receiver.QObject_PTR().GetCthis()
}
var convArg3 = qtrt.CString(member)
defer qtrt.FreeMem(convArg3)
rv, err := qtrt.InvokeQtFunc6("_ZN7QObject7connectEPKS_PKcS1_S3_N2Qt14ConnectionTypeE", qtrt.FFI_TYPE_POINTER, convArg0, convArg1, convArg2, convArg3, arg4)
qtrt.ErrPrint(err, rv)
return int(rv)
}
func QObject_Connect(sender QObject_ITF /*777 const QObject **/, signal string, receiver QObject_ITF /*777 const QObject **/, member string, arg4 int) int {
var nilthis *QObject
rv := nilthis.Connect(sender, signal, receiver, member, arg4)
return rv
}
// /usr/include/qt/QtCore/qobject.h:208
// index:0
// Public static Visibility=Default Availability=Available
// [8] QMetaObject::Connection connect(const QObject *, const char *, const QObject *, const char *, Qt::ConnectionType)
/*
Creates a connection of the given type from the signal in the sender object to the method in the receiver object. Returns a handle to the connection that can be used to disconnect it later.
You must use the SIGNAL() and SLOT() macros when specifying the signal and the method, for example:
QLabel *label = new QLabel;
QScrollBar *scrollBar = new QScrollBar;
QObject::connect(scrollBar, SIGNAL(valueChanged(int)),
label, SLOT(setNum(int)));
This example ensures that the label always displays the current scroll bar value. Note that the signal and slots parameters must not contain any variable names, only the type. E.g. the following would not work and return false:
// WRONG
QObject::connect(scrollBar, SIGNAL(valueChanged(int value)),
label, SLOT(setNum(int value)));
A signal can also be connected to another signal:
class MyWidget : public QWidget
{
Q_OBJECT
public:
MyWidget();
signals:
void buttonClicked();
private:
QPushButton *myButton;
};
MyWidget::MyWidget()
{
myButton = new QPushButton(this);
connect(myButton, SIGNAL(clicked()),
this, SIGNAL(buttonClicked()));
}
In this example, the MyWidget constructor relays a signal from a private member variable, and makes it available under a name that relates to MyWidget.
A signal can be connected to many slots and signals. Many signals can be connected to one slot.
If a signal is connected to several slots, the slots are activated in the same order in which the connections were made, when the signal is emitted.
The function returns a QMetaObject::Connection that represents a handle to a connection if it successfully connects the signal to the slot. The connection handle will be invalid if it cannot create the connection, for example, if QObject is unable to verify the existence of either signal or method, or if their signatures aren't compatible. You can check if the handle is valid by casting it to a bool.
By default, a signal is emitted for every connection you make; two signals are emitted for duplicate connections. You can break all of these connections with a single disconnect() call. If you pass the Qt::UniqueConnection type, the connection will only be made if it is not a duplicate. If there is already a duplicate (exact same signal to the exact same slot on the same objects), the connection will fail and connect will return an invalid QMetaObject::Connection.
Note: Qt::UniqueConnections do not work for lambdas, non-member functions and functors; they only apply to connecting to member functions.
The optional type parameter describes the type of connection to establish. In particular, it determines whether a particular signal is delivered to a slot immediately or queued for delivery at a later time. If the signal is queued, the parameters must be of types that are known to Qt's meta-object system, because Qt needs to copy the arguments to store them in an event behind the scenes. If you try to use a queued connection and get the error message
QObject::connect: Cannot queue arguments of type 'MyType'
(Make sure 'MyType' is registered using qRegisterMetaType().)
call qRegisterMetaType() to register the data type before you establish the connection.
Note: This function is thread-safe.
See also disconnect(), sender(), qRegisterMetaType(), Q_DECLARE_METATYPE(), and Differences between String-Based and Functor-Based Connections.
*/
func (this *QObject) Connectp(sender QObject_ITF /*777 const QObject **/, signal string, receiver QObject_ITF /*777 const QObject **/, member string) int {
var convArg0 unsafe.Pointer
if sender != nil && sender.QObject_PTR() != nil {
convArg0 = sender.QObject_PTR().GetCthis()
}
var convArg1 = qtrt.CString(signal)
defer qtrt.FreeMem(convArg1)
var convArg2 unsafe.Pointer
if receiver != nil && receiver.QObject_PTR() != nil {
convArg2 = receiver.QObject_PTR().GetCthis()
}
var convArg3 = qtrt.CString(member)
defer qtrt.FreeMem(convArg3)
// arg: 4, Qt::ConnectionType=Elaborated, Qt::ConnectionType=Enum, , Invalid
arg4 := 0
rv, err := qtrt.InvokeQtFunc6("_ZN7QObject7connectEPKS_PKcS1_S3_N2Qt14ConnectionTypeE", qtrt.FFI_TYPE_POINTER, convArg0, convArg1, convArg2, convArg3, arg4)
qtrt.ErrPrint(err, rv)
return int(rv)
}
// /usr/include/qt/QtCore/qobject.h:211
// index:1
// Public static Visibility=Default Availability=Available
// [8] QMetaObject::Connection connect(const QObject *, const QMetaMethod &, const QObject *, const QMetaMethod &, Qt::ConnectionType)
/*