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. Will signal /slots degrades the performance in the following case
Forum Updated to NodeBB v4.3 + New Features

Will signal /slots degrades the performance in the following case

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 439 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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by
    #1

    Hi All
    I have class

    class myObject {
     .........
    };
    

    class A {
    public slot :
    addToMap(myObject obj,QColor color) { map1.insert(obj,color); }
    private:
    QMap <myObject ,QColor> map1;
    };

    class B {
    ...
    signal:
    updateColorInB(myObject obj ,QColor>
    public
    showB();
    };

    B::showB() {
        for (int i =0 ; i < 100000000;i++) {
            // get myObject as obj 
            // and QColor  object color
            emit updateColorInB(obj,color);
        }    
    }
    
    
    Will it be slower to use signal sn slots in case we have millions of entries in for loop , 
    
    Will it be faster to use direct method like 
    
    B::showB() {
        A* a = new A; 
        for (int i =0 ; i < 100000000;i++) {
            // get myObject as obj 
            // and QColor  object color
            a->addToMap(obj,color);
        }    
    }
    
    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      if using direct connection it will be only very slightly slower compared to the direct call with the advantage that, using the signal, B does not need to know A exists at all

      The signal overhead is nothing compared to the degrade in performance due to calling myObject and QColor copy constructor every invocation of addToMap. you should REALLY pass the parameters as const references

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      4

      • Login

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