syntax understanding

I was looking at one of the c++ based frameworks. There is a class QMainWindow which uses the below syntax

.....
class QMenu;

class Q_GUI_EXPORT QMainWindow : public QWidget
{
Q_OBJECT

Q_ENUMS(DockOption)
Q_FLAGS(DockOptions)
......

I am struggling to get grips on the syntax here (have got limited exposure to the c++ world)

class QMenu is defined in an another header file, what does the line class QMenu; do in the above code which is in QMainWindow class ?
Also what does Q_GUI_EXPORT do? does it export this class?
What does Q_OBJECT line do ?

Thanks in Advance

class QMenu; is a forward declaration. It says to the compiler that there is a class named QMenu. It makes it possible to have pointers and references to QMenu objects without having to include the header that defines QMenu. To be able to create instances of QMenu, or call any of its member functions you will need the full class definition.

Q_GUI_EXPORT and Q_OBJECT are probably macros. I don't know what they are used for.
Last edited on
Thanks. Probably I need to read more on macros. One additional question though. How do macros help when defined with a class as above in general?
Q_OBJECT

is the part of the mechanism that Qt uses through the Meta Object Compiler, to achieve the ability to have slots & connections, RTTI etc. I think you need to do a lot more reading, to get an understanding of Qt.

http://doc.qt.digia.com/4.7-snapshot/moc.html


GUI's are not trivial things - there can as much learning (if not more) in a GUI, than there is in learning a language like C++. It would be a huge advantage in knowing a reasonable amount about C++ before trying to tackle Qt.

I am not trying to discourage you, I managed to pick up the rudiments of Qt reasonably quickly while I had a limited knowledge of C++. But it took a lot of reading & figuring out. Knowledge is a relative thing, but obviously the more you have, the better off you will be. I guess learning new things has always been a part of the challenge in Computer Science.

Anyway - Good Luck !!! Hope this helped a bit.
thanks a lot, any pointer to Q_GUI_EXPORT macro?

njoy reading and learning so looking forward to the challenge
No worries, read some of the other docs on the website, or google Qt Q_GUI_EXPORT.

Topic archived. No new replies allowed.