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. Understanding signature normalization for signals and slots
Forum Updated to NodeBB v4.3 + New Features

Understanding signature normalization for signals and slots

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 7.7k Views 1 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.
  • JKSHJ Offline
    JKSHJ Offline
    JKSH
    Moderators
    wrote on last edited by JKSH
    #1

    Hi all,

    I've just discovered the concept of signature normalization, and would like to improve my understanding of it. Let's say I have 2 classes:

    class Sender : public QObject
    {
    signals:
        // Emit a copy of the QVector because the object doesn't store a local copy
        void send(QVector<int>, float);
    }
    
    class Receiver : public QObject
    {
    public slots:
        // Avoid making another copy by using const-&
        void receive(const QVector<int> &, float);
    }
    

    Previously, I would make the connection by copying the function prototype, and I used lots of whitespace for readability:

    connect::(  sender, SIGNAL( send(QVector<int>, float) ),
            receiver, SLOT( receive(const QVector<int> &, float) )  );
    

    After some reading, here's my current understanding of the signal/slot connection system. Could someone please check if I've got it right?

    1. A "signature" is a string, comprised of the characters typed into the SIGNAL() and SLOT() macros, or modified by QMetaObject::normalizedSignature()

    2. The meta-object system only stores normalized signatures, so any (probably unnoticeable) "normalization overhead" is only incurred at connection time, not every time the signal is emitted.

    3. In my connection above, I can manually normalize my signatures and avoid a "normalization overhead" by re-writing it as:

        connect::(  sender, SIGNAL(send(QVector<int>,float)),
                receiver, SLOT(receive(QVector<int>,float))  );
    
    1. Only the function prototypes determine if the parameters are passed-by-value or passed-by-reference; the signatures passed into the SIGNAL() and SLOT() macros have no effect on this

    2. In my example classes above, the QVector is copied once each time the signal is emitted. If Receiver::receive() had used pass-by-value instead, the QVector would be copied twice each time the signal is emitted.

    Thanks in advance!

    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

    1 Reply Last reply
    1
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by JKSH
      #2

      I found this quote in the wiki (https://wiki.qt.io/Writing_Qt_Examples ):

      Always specify the full types of the arguments, i.e. const QString & instead of QString, in the interest of keeping things simple for beginners. We’ll mention that you can write the latter in the documentation, but stick to a consistent, simple subset of the Qt language in examples.

      Is this sound advice?

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • K Kaluss referenced this topic on
      • K Kaluss referenced this topic on

      • Login

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