Unsolved Will signal /slots degrades the performance in the following case
-
Hi All
I have classclass 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); } }
-
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