Results 1 to 4 of 4

Thread: signal/slot or subclassed event?

  1. #1
    Join Date
    Oct 2010
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default signal/slot or subclassed event?

    hi all,

    in my program i need to trigger an event whenever a subclassed QGraphicsItem is clicked, this event will affect lots of widgets including the parent scene of the item.. so should i re implement the event in the subclass or is it better to use a signal/slot combination?
    Last edited by liqxpil; 3rd November 2010 at 12:49.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: signal/slot or subclassed event?

    AFAIK, QGraphicsItem is not a QObject, so it should not be possible to use signals/slots with a QGraphicsItem, but you could use QGraphicsObject.

    Nothing in what your wrote helps to decide which would be better.
    As a thumb rule though, I would go for signals/slots as long as it is possible, and means less work than reimplemnting events.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    liqxpil (4th November 2010)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: signal/slot or subclassed event?

    I would probably reimplement mouse events for the scene or reimplement the item to emit a signal and catch that in the scene. But the first approach is probably much simpler.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    liqxpil (4th November 2010)

  6. #4
    Join Date
    Oct 2010
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: signal/slot or subclassed event?

    yup my question is which to do
    if its not clear enough... i need to modify the items parent scene (add more items etc..) and other irrelevant widgets (not the scenes parent) based on the mouse events
    i guess ill go with event re implementing since i subclassed already.. just not sure its the best thing to do..
    Last edited by liqxpil; 4th November 2010 at 11:25.

Similar Threads

  1. Subclassed qlistwidget event handling problem
    By Annihilator in forum Qt Programming
    Replies: 9
    Last Post: 13th February 2010, 18:55
  2. signal and slot across threads having event loop
    By travis in forum Qt Programming
    Replies: 6
    Last Post: 5th November 2007, 23:56
  3. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52
  4. Replies: 4
    Last Post: 23rd January 2006, 16:51
  5. What's the relationship between signal/slot and event?
    By twosnowman in forum Qt Programming
    Replies: 4
    Last Post: 11th January 2006, 17:13

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.