K
K
Kirill H2016-12-11 23:45:30
Qt
Kirill H, 2016-12-11 23:45:30

What does "Q_DECL_OVERRIDE" do in Qt?

I understand Qt, here I was reviewing a simple project in parts and ran into a strange function declaration:
For example:
void advance(int step) Q_DECL_OVERRIDE;
or:
QRectF boundingRect() const Q_DECL_OVERRIDE;
I looked on the Qt website why this macro is needed, as I understand it, to generate errors for non-overridden virtual functions.
But here the functions are not virtual at all. Explain who knows what the macro "Q_DECL_OVERRIDE" is and why it is needed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2016-12-12
@vt4a2h

This macro expands as override if there is C++11 support, and as empty space otherwise. What is actually written on the site: "It expands to "override" if your compiler supports that C++11 contextual keyword, or to nothing otherwise".
What the override keyword means can be easily Googled: en.cppreference.com/w/cpp/language/override.
For virtual functions, it is good practice to write the word virtual only once - usually in the interface, this does not stop them from being virtual. In other cases, override.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question