If a C++ class is defined with Q_OBJECT macro then editor show a syntax error: class Foo: public QObject { Q_OBJECT _p_ublic: // <-- red underscore is shown under the "p" letter ... } As shown above the error is indicated at the 'public' keyword. The tooltip says: Problem in Parser: Unexpected token 'public' As the result the class members are not recognized (autocompletion does not work). When Q_OBJECT macro is removed from the source the syntax error disappears. The Q_OBJECT macro itself is recognized correctly. The tooltip shows that it is defined in /usr/include/qt5/QtCore/qobjectdefs.h :187 and following preprocessed body: ------------------------------------------ public: template <typename ThisObject> inline void qt_check_for_QOBJECT_macro(const ThisObject& _q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } _Pragma("GCC diagnostic push") static const QMetaObject staticMetaObject; virtual const QMetaObject* metaObject() const; virtual void* qt_metacast(const char*); virtual int qt_metacall(QMetaObject::Call, int, void**); static inline QString tr(const char* s, const char* c = nullptr , int n = -1) { return staticMetaObject.tr(s, c, n); } static inline QString trUtf8(const char* s, const char* c = nullptr , int n = -1) { return staticMetaObject.tr(s, c, n); } private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject*, QMetaObject::Call, int, void**); _Pragma("GCC diagnostic pop") struct QPrivateSignal {}; ------------------------------------------ With Qt4 it is working correctly. It was also working correctly with Qt 5.5. The problem appeared after upgrade to Qt 5.6.1. I have kdevplatform 1.7.3. Using CMake build system with GCC in the project. Reproducible: Always
I can confirm this. I've had the exact same problem. Someone in the IRC channel (ogoffart) said that adding "#define _Pragma(...)" before including any Qt headers fixes the problem, and indeed it does: #define _Pragma(...) #include <QWidget> class Thing : public QWidget { Q_OBJECT public: // there is no longer a parser error here Thing(QWidget* parent = 0); };
Git commit 8769c228a55303c2b6a19f10e05ebc01067108bf by Milian Wolff. Committed on 17/08/2016 at 20:12. Pushed by mwolff into branch '4.7'. Ignore C99 _Pragma macros Fixes parsing of Q_OBJECT among other things. M +8 -0 languages/cpp/setuphelpers.cpp http://commits.kde.org/kdevelop/8769c228a55303c2b6a19f10e05ebc01067108bf