Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Polymorphism fails with derived class of QGraphicsScene

Polymorphism fails with derived class of QGraphicsScene

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 485 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LauraB
    wrote on last edited by
    #1

    Hi,

    I've derived QGraphicsScene into a class called DiagramScene like this :

    DiagramScene.h

    #include <QGraphicsScene>
    
    class QGraphicsSceneMouseEvent;
    class QMenu;
    class QPointF;
    class QGraphicsLineItem;
    class QFont;
    class QGraphicsTextItem;
    class QColor;
    
    class DiagramScene : public QGraphicsScene
    {
        Q_OBJECT
    
    public:
        explicit DiagramScene(QMenu *itemMenu, QObject *parent = 0);
      // ... The rest ain't relevant for the problem IMO
    };
    

    DiagramScene constructor:

    DiagramScene::DiagramScene(QMenu *itemMenu, QObject *parent)
        : QGraphicsScene(parent)
    {
        // irrelevant code, this was just to show you 
        // i called QGraphicsScene constructor at initialization
    }
    

    And then, the problem :

    // I voluntarily simplified the code to illustrate the problem
    DiagramScene myDiagramScene(....);
    QGraphicsView myGraphicView(....);
    myGraphicView->setScene(&myDiagramScene);
    // At compilation I get this error :
    // No matching function for call to QGraphicsView::setScene(DiagramScene*)
    //  Candidate : QGraphicsView::setScene(QGraphicsScene*)
    

    Please correct me if I'm wrong, which I certainly am, but I thought i would benefit from the polymorphism mechanism here.
    This code works if I cast the pointer into a QGraphicsScene pointer, but I feel like this should work without the case.

    Does someone have a clue?
    Thanks a lot for reading !

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Asperamanca
      wrote on last edited by
      #2

      First thing I would check is your #includes. It sounds like the compiler at that point doesn't know the two classes are related - I often get this when a class is forward-declared, but I don't have the proper include where I want to convert types.

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved