Results 1 to 3 of 3

Thread: Multiple Inheritance for QGraphicsItem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2008
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Multiple Inheritance for QGraphicsItem

    Hello,
    I am using QT 4.4.0 for designing a circuit editor. I am using Qt's Graphics View framework for drawing different elements of circuit, text, pixmaps and even plots (embedding QwtPlotWidget in QGraphicsProxyWidget class).
    I want to have these different elements derived from a common class, lets call it base, and move the functionality common to them in base. Base needs to reimplement some of the methods defined in QGraphicsItem class (itemChange() to mention one), and hence has to derive from QGraphicsItem class. However, this design leads to diamond inheritance issue (as the classes deriving from base also have to derive from classes like QGraphicsPixmapItem and QGraphicsProxyWidget which derive from QGraphicsPixmapItem). Unfortunately, none of the classes given by Qt which derive from QGraphicsPixmapItem (like QGraphicsPixmapItem) inherit it virtually, and put a lot of restriction on my design. Can anyone please suggest me a solution or workaround?

    Thanks in advance,
    Pankaj

    Given below is the pseudo code depicting my problem:

    Qt Code:
    1. class Element : public QGraphicsPixmapItem
    2. {
    3. //Lots of common code
    4. QVariant itemChange ( GraphicsItemChange change, const QVariant & value )
    5. { //Update certain common data upon state change, common to all}
    6. }
    7.  
    8. class TextElement : public Element, public QGraphicsTextItem
    9. {
    10. }
    11.  
    12. class Plot : public QwtPlotWidget, public Element
    13. {
    14. }
    15.  
    16. class scene : public QGraphicsScene
    17. {
    18. TextElement *t = new TextElement;
    19. Plot *p = new Plot;
    20. addItem( t); // Problem: Ambiguous conversion from TextElement* to QGraphicsItem*
    21. addItem(p);//Problem :Ambiguous conversion from Plot* to QGraphicsItem*
    22. //Also, problem while directly or indirectly accessing itemChange() ( ambiguous access)
    23. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 1st July 2008 at 08:10. Reason: missing [code] tags

Similar Threads

  1. Object and multiple inheritance for interfaces
    By brcain in forum Qt Programming
    Replies: 8
    Last Post: 29th June 2021, 15:29
  2. QThread and Multiple inheritance
    By ^NyAw^ in forum General Programming
    Replies: 6
    Last Post: 10th January 2008, 10:50
  3. Multiple Inheritance & Qt
    By kefeng.chen in forum Qt Programming
    Replies: 8
    Last Post: 21st March 2006, 18:37
  4. Multiple inheritance & Qt
    By dublet in forum Qt Programming
    Replies: 11
    Last Post: 8th March 2006, 08:12
  5. Multiple Inheritance
    By sunil.thaha in forum General Programming
    Replies: 4
    Last Post: 21st February 2006, 04:00

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.