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:

    @#ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QtGui/QMainWindow>

    //
    /
    Main application window for QSimulate /
    /
    /

    class MainWindow : public QMainWindow
    {
    public:
    MainWindow(); // constructor
    };

    #endif // MAINWINDOW_H@

    where in the world is one supposed to place:

    @class Scene;

    private:
    Scene* m_scene; // scene representing the simulated landscape@

    I've tried several locations - none of which make the compiler happy.

    Thx!



  • 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".

    @#ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QtGui/QMainWindow>

    //
    /
    Main application window for QSimulate /
    /
    /
    class Scene;

    class MainWindow : public QMainWindow
    {
    public:
    MainWindow(); // constructor

    private:
    Scene* m_scene; // scene representing the simulated landscape

    };

    #endif // MAINWINDOW_H@



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.