File indexing completed on 2024-05-05 05:41:37

0001 #include <QtCore/QObject>
0002 
0003 class MyObject;
0004 
0005 MyObject* somefunc()
0006 {
0007     return nullptr;
0008 }
0009 
0010 static MyObject * s_obj;
0011 
0012 class MyObject : public QObject
0013 {
0014 public:
0015     MyObject();
0016     void pub();
0017     MyObject* memberFunc() const;
0018     MyObject *another;
0019 private:
0020     void priv();
0021 
0022 public slots:
0023     void pubSlot();
0024 
0025 signals:
0026     void sig();
0027 
0028 private Q_SLOTS:
0029     void privSlot();
0030 
0031 protected:
0032     void prot();
0033     Q_SIGNAL void singularSig();
0034     Q_SLOT void singularSlot();
0035 };
0036 
0037 void MyObject::pub()
0038 {
0039     emit  prot(); // Warning: emit on non slot.
0040     sig(); // Warning: missing emit
0041     prot(); // OK
0042     pub(); // OK
0043     priv(); // OK
0044     privSlot(); // OK
0045     Q_EMIT privSlot(); // Warning
0046     Q_EMIT somefunc()->sig(); // OK
0047     somefunc()->sig(); // Warning
0048     Q_EMIT memberFunc()->sig(); // OK
0049     memberFunc()->sig(); // Warning
0050     emit another->sig(); // OK
0051     emit s_obj->sig(); // OK
0052 }
0053 
0054 
0055 MyObject::MyObject()
0056 {
0057     emit sig(); // Warning
0058     emit another->sig(); // OK;
0059     emit memberFunc()->sig(); // OK;
0060     [this]{ emit sig(); }; // OK
0061     emit singularSig(); // Warning
0062     singularSlot(); // OK
0063 }
0064 
0065 void MyObject::singularSlot()
0066 {
0067     singularSig(); // Warning
0068 }
0069 
0070 struct NotQObject
0071 {
0072     QObject *o;
0073     void test1() {}
0074     void test()
0075     {
0076         test1(); // OK
0077         emit test1(); // Warning
0078         emit o->destroyed(); // OK
0079     }
0080 };
0081 
0082 class TestBug373947 : public QObject
0083 {
0084     int method()
0085     {
0086         return otherMethod(); // OK
0087     }
0088 
0089 Q_SIGNALS:
0090     void someSignal();
0091 
0092 public:
0093     int otherMethod();
0094 };