Results 1 to 2 of 2

Thread: Adding signals/slots (QObject functionality) to QGraphicsItem: performance hit?

  1. #1
    Join Date
    Feb 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Adding signals/slots (QObject functionality) to QGraphicsItem: performance hit?

    I want to add signals/slots to a QGraphicsItem so I can reach QGraphicsItemObjects from another thread. There are two options that I know of: use QGraphicsObject or inherit from QObject and QGraphicsItem.

    Using QGraphicsObject
    This is assumed to be slow. According to this answer on stackoverflow QGraphicsObjects are slow because of their implementation. When I look in the source of QGraphicsObjects I can see a lot of signals being emitted according to changes made to the object. To me this seems a plausible argument for why QGraphicsObjects are slow, but I think this performance hit (if it really is one) can be avoided by the second solution.

    Inheriting from QObject and QGraphicsItem.
    When constructing a class that inherits from QObject and QGraphicsItem it seems that you get the most interesting feature of QGraphicsObject minus the performance hit: you are able to define slots and emit signals in your class but you don't inherit the default implementation of QGraphicsObject that would constantly emit signals on changes you might not be interested in. You are now able to emit signals but don't have to worry about signals being emitted for things you don't care about (x value that changes emits a signal in QGraphicsObject but not in this solution).

    Summary of my question
    • Are QGraphicsObjects really slower than QGraphicsItems?
    • If they are, is it because the implementation emits signals (and emitting signals is a
      big performance hit)?
    • And if so, does the second solution (multiple inheritance) avoid this penalty?

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 69 Times in 67 Posts

    Default Re: Adding signals/slots (QObject functionality) to QGraphicsItem: performance hit?

    I can only give a general answer to this. I haven't done any benchmarking on this one. Emitting signals (basically calling the signal function) takes time. It runs through the connected signals and slots and executes those immediately when the connection is direct. Signal-slot connections are string based, so string comparison is involved and may have an impact. So there are some things that may influence speed here. The most significant of those is hard to pin-point. I'm pretty sure the Trolls have improved the speed in their slot discovery to the point where not much speed is to be gained. However, depending on the implementation, the length of the signal & slot names and the amount of arguments may or may not have an impact. When using direct connections, the execution speed of the directly connected slots called as a result of the signal emission is also significant -- they are executed serially and immediately.

    Does the second solution then avoid this penalty if you provide equally named signals and emit them at the same rate? No.

    The real question is of course where the performance hit is coming from. A proper profiling session has to be done to determine this.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

Similar Threads

  1. QGraphicsItem doesn't inherit QObject?
    By xyzt in forum Qt Programming
    Replies: 6
    Last Post: 26th September 2011, 14:59
  2. Performance issue when using signals
    By baluk in forum Newbie
    Replies: 2
    Last Post: 18th November 2010, 04:07
  3. Moving QObject to QThread causes signals to stop working
    By Ban-chan in forum Qt Programming
    Replies: 8
    Last Post: 13th July 2010, 21:39
  4. Signals and Slots - Moc QObject Problem
    By GBayo1 in forum Qt Programming
    Replies: 6
    Last Post: 22nd March 2010, 16:35
  5. Dynamic widgets adding and connecting signals& slots
    By jjbabu in forum Qt Programming
    Replies: 2
    Last Post: 22nd May 2009, 12:36

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.