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. QTimer slot not getting called correctly....
Forum Updated to NodeBB v4.3 + New Features

QTimer slot not getting called correctly....

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 349 Views
  • 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.
  • J Offline
    J Offline
    Jyothi
    wrote on last edited by
    #1

    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

    1. 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

    2. 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

    JonBJ Christian EhrlicherC 2 Replies Last reply
    0
    • J Jyothi

      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

      1. 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

      2. 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

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @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.
      J 1 Reply Last reply
      0
      • J Jyothi

        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

        1. 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

        2. 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

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @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...

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        J 1 Reply Last reply
        1
        • Christian EhrlicherC Christian Ehrlicher moved this topic from Qt Creator and other tools on
        • JonBJ JonB

          @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.
          J Offline
          J Offline
          Jyothi
          wrote on last edited by
          #4

          @JonB

          • 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)

          1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            @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...

            J Offline
            J Offline
            Jyothi
            wrote on last edited by
            #5

            @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

            1 Reply Last reply
            0

            • Login

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