Search code examples
c++qtg++signals-slots

g++ Parse error at ":"


g++ is reporting a parse error with the code below:

class Sy_timeLineDelegateScene : public QGraphicsScene
{
    Q_OBJECT
public:
    Sy_timeLineDelegateScene( Sy_animPropertyTimeLine* timeline,
                              Sy_animClock* clock,
                              QObject* parent = nullptr );
    virtual ~Sy_timeLineDelegateScene() {}

protected slots:   // Parse error at ":"
    typedef QMap< Sy::Frame, Sy_timeLineDelegateKey* > DelegateTimeLine;
...

My class is derived from QObject and I have declared the Q_OBJECT macro before the error, but if I comment out the slots part, it compiles fine. I have used Qt for years and never seen this before, it must be something stupid, but I can't see what's causing the problem.


Solution

  • The "slots" and "signals" sections in a class definition should only contain functions; neither types nor member variables.

    You should move the typedef in a public, protected or private section:

    class Sy_timeLineDelegateScene : public QGraphicsScene
    {
        Q_OBJECT
    public:
        Sy_timeLineDelegateScene( Sy_animPropertyTimeLine* timeline,
                                  Sy_animClock* clock,
                                  QObject* parent = nullptr );
        virtual ~Sy_timeLineDelegateScene() {}
    
        typedef QMap< Sy::Frame, Sy_timeLineDelegateKey* > DelegateTimeLine;
    
    protected slots:
    ...