QTimer slot not getting called correctly....
-
I'm using Qt creator C++ (Qt Creator 4.11.1 based on Qt 5.14.1, Qt 5.14.2 (gcc_64) compiler) with QGIS to display and move icons on QGIS map. There is a QTimer, which is started for 100ms (timer->start(100)), for moving the icons on map
I did this in two ways
-
I'm using QgsFeature to show icons like QgsFeature (icon is set using QgsSymbol) is added to QgsVectorLayer and QgsVectorLayer is added to QgsMapCanvas. In every timeout() SLOT function, I'm removing all features from layer and adding them to Vectorlayer according to their new position
-
I'm using QgsRubberBand to show and move icons like, setting the icon using setIcon() and adding Rubberband to mapcanvas using setToGeometry(). In every timeout() SLOT function, I'm setting Icon and geometry to move the icon
When I do this, timeout() SLOT is not getting called for every 100ms. Even though SLOT function is completely executed, it is taking time to call the next timeout() SLOT function.
It is taking more than 200-300ms to call the next timeout() SLOT function when I follow the 1st procedure, it is taking 150-250ms when I follow the 2nd procedure
-
-
I'm using Qt creator C++ (Qt Creator 4.11.1 based on Qt 5.14.1, Qt 5.14.2 (gcc_64) compiler) with QGIS to display and move icons on QGIS map. There is a QTimer, which is started for 100ms (timer->start(100)), for moving the icons on map
I did this in two ways
-
I'm using QgsFeature to show icons like QgsFeature (icon is set using QgsSymbol) is added to QgsVectorLayer and QgsVectorLayer is added to QgsMapCanvas. In every timeout() SLOT function, I'm removing all features from layer and adding them to Vectorlayer according to their new position
-
I'm using QgsRubberBand to show and move icons like, setting the icon using setIcon() and adding Rubberband to mapcanvas using setToGeometry(). In every timeout() SLOT function, I'm setting Icon and geometry to move the icon
When I do this, timeout() SLOT is not getting called for every 100ms. Even though SLOT function is completely executed, it is taking time to call the next timeout() SLOT function.
It is taking more than 200-300ms to call the next timeout() SLOT function when I follow the 1st procedure, it is taking 150-250ms when I follow the 2nd procedure
@Jyothi
Although I know nothing about QGIS, there are two possibilities:- The actions taken during the slot code take the time you say. Being greater than the 100ms timer timeout, the next timeout can only be raised when the slot from the previous timeout is finished. The next timeout will not be raised while a previous one's slot has not returned.
- You have some other code running after the timeout slot you mention which uses further time above 100ms or the time taken to execute the slot code. Such as, say, a "sleep" function, which we see so often in users code here.
-
-
I'm using Qt creator C++ (Qt Creator 4.11.1 based on Qt 5.14.1, Qt 5.14.2 (gcc_64) compiler) with QGIS to display and move icons on QGIS map. There is a QTimer, which is started for 100ms (timer->start(100)), for moving the icons on map
I did this in two ways
-
I'm using QgsFeature to show icons like QgsFeature (icon is set using QgsSymbol) is added to QgsVectorLayer and QgsVectorLayer is added to QgsMapCanvas. In every timeout() SLOT function, I'm removing all features from layer and adding them to Vectorlayer according to their new position
-
I'm using QgsRubberBand to show and move icons like, setting the icon using setIcon() and adding Rubberband to mapcanvas using setToGeometry(). In every timeout() SLOT function, I'm setting Icon and geometry to move the icon
When I do this, timeout() SLOT is not getting called for every 100ms. Even though SLOT function is completely executed, it is taking time to call the next timeout() SLOT function.
It is taking more than 200-300ms to call the next timeout() SLOT function when I follow the 1st procedure, it is taking 150-250ms when I follow the 2nd procedure
@Jyothi said in QTimer slot not getting called correctly....:
I'm removing all features from layer and adding them to Vectorlayer according to their new position
Why? I would guess this will take quite some time...
-
-
C Christian Ehrlicher moved this topic from Qt Creator and other tools on
-
@Jyothi
Although I know nothing about QGIS, there are two possibilities:- The actions taken during the slot code take the time you say. Being greater than the 100ms timer timeout, the next timeout can only be raised when the slot from the previous timeout is finished. The next timeout will not be raised while a previous one's slot has not returned.
- You have some other code running after the timeout slot you mention which uses further time above 100ms or the time taken to execute the slot code. Such as, say, a "sleep" function, which we see so often in users code here.
- I Checked the time of execution for the slot function by keeping QTime::currentTime.toString() at the end and start of the function, it is taking hardly 50ms to 80ms max. But after the function is completely executed, the next slot is taking time to get called
for example,
SLOT FUNCTION STRT : 13:12:48:505
SLOT FUNCTION END : 13:12:48:555 to 13:12:48:855 (any value in this range)So, according to QTimer, SLOT FUNCTION should start at 13:12:48:605. But SLOT FUNCTION is starting at 13:12:48:655 to 13:12:48:855 (any value in this range)
I'm thinking like, function is executed within no time, but for icons get updated on map is taking time (like rendering is taking time)
-
@Jyothi said in QTimer slot not getting called correctly....:
I'm removing all features from layer and adding them to Vectorlayer according to their new position
Why? I would guess this will take quite some time...
@Christian-Ehrlicher said in QTimer slot not getting called correctly....:
Why? I would guess this will take quite some time...
That code was from one of the previous employees, I tried to optimize this with QgsRubberband and doing setToGeometry() for the rubberband