| 1 |
#include <QtCore/QObject> |
| 2 |
#include <QtDBus/QDBusPendingReply> |
| 3 |
#include <memory> |
| 4 |
struct A {}; |
| 5 |
struct NonNamespacedGadget { |
| 6 |
Q_GADGET |
| 7 |
}; |
| 8 |
namespace TestMe { class Dummy {};} |
| 9 |
namespace NS { |
| 10 |
struct MyType {}; |
| 11 |
|
| 12 |
struct NamespacedGadget { |
| 13 |
Q_GADGET |
| 14 |
}; |
| 15 |
|
| 16 |
enum EnumFoo { EnumFoo1 }; |
| 17 |
|
| 18 |
class MyObject : public QObject |
| 19 |
{ |
| 20 |
Q_OBJECT |
| 21 |
Q_PROPERTY(NS::MyType foo READ foo) // OK, not gadget |
| 22 |
Q_PROPERTY(MyType foo1 READ foo) // OK, not gadget |
| 23 |
Q_PROPERTY(EnumFoo enumFoo READ enumFoo CONSTANT) // OK |
| 24 |
Q_PROPERTY(NamespacedGadget namespacedGadget READ namespacedGadget CONSTANT) // Warn, gadget |
| 25 |
Q_PROPERTY(NS::NamespacedGadget namespacedGadget2 READ namespacedGadget2 CONSTANT) // OK |
| 26 |
Q_PROPERTY(NonNamespacedGadget nonNamespacedGadget READ nonNamespacedGadget CONSTANT) // OK |
| 27 |
Q_SIGNALS: |
| 28 |
void mysig(NS::MyType); |
| 29 |
void mysig2(NS::MyType &); // Warn |
| 30 |
void mysig3(NS::MyType); |
| 31 |
void mysig4(const NS::MyType &); |
| 32 |
void mysig5(A); |
| 33 |
void mysig6(const A); |
| 34 |
void mysig7(const A *); |
| 35 |
void mysig8(A *); |
| 36 |
public Q_SLOTS: |
| 37 |
void myslot1(NS::MyType); |
| 38 |
void myslot2(NS::MyType); // Warn |
| 39 |
void myslot3(NS::MyType); |
| 40 |
void myslot4(const NS::MyType &); |
| 41 |
void myslot5(A); |
| 42 |
void myslot6(const A); |
| 43 |
void myslot7(const A *); |
| 44 |
void myslot8(A *); |
| 45 |
public: |
| 46 |
Q_INVOKABLE void myinvokable1(NS::MyType); |
| 47 |
Q_INVOKABLE void myinvokable2(NS::MyType); // Warn |
| 48 |
Q_INVOKABLE void myinvokable3(NS::MyType); |
| 49 |
Q_INVOKABLE void myinvokable4(const NS::MyType &); |
| 50 |
Q_INVOKABLE void myinvokable5(A); |
| 51 |
Q_INVOKABLE void myinvokable6(const A); |
| 52 |
Q_INVOKABLE void myinvokable7(const A *); |
| 53 |
Q_INVOKABLE void myinvokable8(A *); |
| 54 |
Q_INVOKABLE NS::MyType* myinvokable9(NS::MyType); // Warn |
| 55 |
NS::MyType foo(); |
| 56 |
NamespacedGadget namespacedGadget() const; |
| 57 |
NamespacedGadget namespacedGadget2() const; |
| 58 |
NonNamespacedGadget nonNamespacedGadget() const; |
| 59 |
EnumFoo enumFoo() const; |
| 60 |
}; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
template<typename T> using DummyListAlias = QList<T>; |
| 65 |
namespace { // annonymous |
| 66 |
struct AnnonFoo {}; |
| 67 |
}; |
| 68 |
|
| 69 |
using namespace std; // pair<bool,QualMe> is returned for one method, the check should warn about the missing "std::" prefix |
| 70 |
class MyObj2 : public QObject |
| 71 |
{ |
| 72 |
public: |
| 73 |
struct QualMe {}; |
| 74 |
using MyList = QList<QualMe>; // QualMe is not fully qualified here, but it shouldn't matter when using the typedef |
| 75 |
Q_OBJECT |
| 76 |
Q_SIGNALS: |
| 77 |
void mySig(AnnonFoo); |
| 78 |
public Q_SLOTS: |
| 79 |
inline std::pair<bool, MyObj2::QualMe> unqualPairParam() {return {};} // Warn |
| 80 |
inline std::pair<bool, MyObj2::QualMe> unqualPairClass() {return {};} // Warn |
| 81 |
inline std::pair<bool, MyObj2::QualMe> fullyQUalPair() {return {};} // OK |
| 82 |
inline MyObj2::MyList typeAlias() {return {};} // WARN |
| 83 |
inline QList<MyObj2::QualMe> genericWithoutFullyQual() {return {};} // WARN |
| 84 |
inline QList<MyObj2::QualMe> genericFullyQual() {return {};} // OK |
| 85 |
inline QStringList qstringListTypealias() {return {};} // OK |
| 86 |
inline MyObj2::MyList fullTypeAlias() {return {};} // OK |
| 87 |
inline QDBusPendingReply<MyObj2::QualMe> unqualGenericDbusReply() {return {};} // WARN |
| 88 |
inline QDBusPendingReply<bool> boolDbusReply() {return {};} // OK |
| 89 |
inline QDBusPendingReply<> voidDbusReply() {return {};} // OK |
| 90 |
inline QDBusPendingReply<MyObj2::MyList> typedefInGeneric() {return {};} // WARN |
| 91 |
inline void nestedGeneric(QDBusPendingReply<std::shared_ptr<MyObj2>>) {} // OK |
| 92 |
inline void nestedNotFullyQualifiedGeneric(QDBusPendingReply<std::shared_ptr<MyObj2::MyList>>) {} // WARN |
| 93 |
inline const MyObj2::MyList& notQualWithModifier() {return lst;}; |
| 94 |
DummyListAlias<int> myList() { return {1,2,3};}; |
| 95 |
|
| 96 |
// const modifiers |
| 97 |
inline std::shared_ptr<const MyObj2::QualMe> returnSharedPtrNotQual() // WARN |
| 98 |
{ |
| 99 |
return std::shared_ptr<const QualMe>(new QualMe()); |
| 100 |
} |
| 101 |
inline std::shared_ptr<const MyObj2::QualMe> returnSharedPtr() |
| 102 |
{ |
| 103 |
return std::shared_ptr<const QualMe>(new QualMe()); |
| 104 |
} |
| 105 |
inline std::shared_ptr<const MyObj2::QualMe> returnSharedPtrSpaces() |
| 106 |
{ |
| 107 |
return std::shared_ptr<const QualMe>(new QualMe()); |
| 108 |
} |
| 109 |
inline const MyObj2::QualMe returnConstNoGeneric() |
| 110 |
{ |
| 111 |
return QualMe(); |
| 112 |
} |
| 113 |
Q_INVOKABLE TestMe::Dummy *qual1() const; |
| 114 |
Q_INVOKABLE TestMe::Dummy* qual2() const; |
| 115 |
Q_INVOKABLE MyObj2::QualMe * unqualifiedPtr() const; |
| 116 |
private: |
| 117 |
MyList lst; |
| 118 |
}; |
| 119 |
Q_DECLARE_METATYPE(MyObj2::QualMe); |
| 120 |
Q_DECLARE_METATYPE(std::shared_ptr<MyObj2::MyList>); |
| 121 |
|
| 122 |
#if QT_VERSION_MAJOR == 5 |
| 123 |
#include "main.qt5.moc_" |
| 124 |
#elif Q_MOC_OUTPUT_REVISION == 69 |
| 125 |
#include "main.qt6.moc_69" |
| 126 |
#else |
| 127 |
#include "main.qt6.moc_" |
| 128 |
#endif |