May 11, 2012

lapin lapin
Lab Rat
9 posts

QtCreator part 3 tutorial

 

In the section titled Creating the Scene and View the user is instructed to add a forward declaration for:

class Scene;

then to create a private variable to store a pointer to the scene:

private: Scene* m_scene;

With the header file originally looking like this:

  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QtGui/QMainWindow>
  5.  
  6. /*************************************************************************************/
  7. /*********************** Main application window for QSimulate ***********************/
  8. /*************************************************************************************/
  9.  
  10. class MainWindow : public QMainWindow
  11. {
  12. public:
  13.   MainWindow();                       // constructor
  14. };
  15.  
  16. #endif // MAINWINDOW_H

where in the world is one supposed to place:

  1. class Scene;
  2.  
  3. private:
  4.   Scene*       m_scene;               // scene representing the simulated landscape

I’ve tried several locations – none of which make the compiler happy.

Thx!

2 replies

May 11, 2012

lapin lapin
Lab Rat
9 posts

Actually, I think I just got it:

It really would have helped if, in the tutorial, it spelled out “add the new class declaration before the MainWindow class, then add the private variable declaration to the MainWindow class”.

  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QtGui/QMainWindow>
  5.  
  6. /*************************************************************************************/
  7. /*********************** Main application window for QSimulate ***********************/
  8. /*************************************************************************************/
  9. class Scene;
  10.  
  11. class MainWindow : public QMainWindow
  12. {
  13. public:
  14.   MainWindow();                       // constructor
  15.  
  16. private:
  17.   Scene*       m_scene;               // scene representing the simulated landscape
  18.  
  19. };
  20.  
  21.  
  22. #endif // MAINWINDOW_H

May 11, 2012

DerManu DerManu
Robot Herder
451 posts

I guess it is assumed the very basics of C++ are known, in this case how forward-declaration works and what it’s good for.
If you’re new to (C++)programming, I tend to discourage starting with Qt right away. While Qt is a great role model for clean programming/naming/API design (I myself have learned a lot from the Qt wizards), it uses some quite tricky mechanisms that are way over the head of new programmers, and may distract from actually learning C++ (Meta object RTTI/MOC, qmake, Signals&Slots, pimpl, the whole event loop system, the different ways of memory management).
The STL is more down to earth regarding those things. And as a bonus, after learning to walk with C++ and STL a little, you’ll appreciate Qt much more and feel like flying.

 
  ‹‹ How to use QTreeView::setRowHidden      IntelliSense behaviour in a QTextEdit... ››

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