March 17, 2012

aakashbhowmick aakashbhowmi..
Lab Rat
1 posts

Clarification required in MainWindow Example

 

With reference to the MainWindow example here : http://qt-project.org/doc/qt-4.8/examples-mainwindow.html

If you look into the mainwindow.h file ( http://qt-project.org/doc/qt-4.8/mainwindows-application-mainwindow-h.html ) , at the top class QAction has been defined , but nowhere could I find any definition of the class.

However, in the mainwindow.cpp file ( http://qt-project.org/doc/qt-4.8/mainwindows-application-mainwindow-cpp.html ) in the createActions method of MainWindow class, an object of QAction is being created by calling its constructor. Howver, I could not find any definition of the constructor.

Since QActios is a library class, shouldn’t it be included in the code using ‘#include’ ? Where has QAction class been defined ? What’s going on here ?

2 replies

March 17, 2012

koahnig koahnig
Mad Scientist
2099 posts

welcome to devnet

The class statement in this example QAction tells the compiler that QAction is a class. You need this that the compiler knows what to do with the QAction pointer definitions. It does not need more infos at this point.

There is an include for QtGui in the mainwindows. This include basically summarizes a number of other includes (QAction is part of them).
Within the .cpp file the compiler finally needs to know how to handle QAction. This is the latest point to define QAction which is done through the QtGui include.

March 17, 2012

koahnig koahnig
Mad Scientist
2099 posts

Here is a link for some explanation on this [flipcode.com]

 
  ‹‹ Using Qt to generate stringlist combinations      CSS inheritance in QGraphicsView ››

You must log in to post a reply. Not a member yet? Register here!