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. What does QTimer::singleShot(0, this, SLOT(SlotName))); do
Forum Update on Monday, May 27th 2025

What does QTimer::singleShot(0, this, SLOT(SlotName))); do

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

    In my function

    void myView::mouseReleaseEvent(QMouseEvent* event)
    {
    if (action == move) {
    QTimer::singleShot(0, this, SLOT(moveItems()));
    }
    }

    }

    void myView::mouseReleaseEvent(QMouseEvent* event)
    {
    if (action == move) {
    // handle move
    // update the x y coordinates in our own customised database code
    }

    }

    My question is I am not able to get What does QTimer::singleShot(0, this, SLOT(SlotName))); do ?

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by dheerendra
      #2

      It will call moveitems function immediately only once. Just look at documentation as well. "a QTimer with a timeout of 0 will time out as soon as all the events in the window system's event queue have been processed".

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      6
      • Q Offline
        Q Offline
        Qt Enthusiast
        wrote on last edited by
        #3

        Is it a good practice to call moveitems once after mouseReleaseEvent , to avoid many calls to moveItems ?

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          In your case every time mouse is released called moveitems function will be called. May b this is done with purpose as this has effect of calling moveitems function as event loop processing. Wha is the idea behind calling moveitems ? What does it do ?

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          6
          • Q Offline
            Q Offline
            Qt Enthusiast
            wrote on last edited by
            #5

            myView is QGraphicsView

            We have our own parallel database items for objects shown in myView and

            The moveItems update the x and y coordinates of these database objects s
            we need to update the x and y coordinates of these database objects so the GUI and database are in sync

            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by
              #6

              Understood now. There is no need to move your single shot method outside mouserelease. That is the right way. Why did u think of moving single shot function outside your mouserelease ?

              Dheerendra
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              1 Reply Last reply
              7
              • Q Offline
                Q Offline
                Qt Enthusiast
                wrote on last edited by
                #7

                sorry for delayed reply I was just trying understand the design , I think your answers solved my quries

                1 Reply Last reply
                0
                • dheerendraD Offline
                  dheerendraD Offline
                  dheerendra
                  Qt Champions 2022
                  wrote on last edited by
                  #8

                  Super. Just move the issue to "Solved" state. It helps other. Enjoy Qt!!

                  Dheerendra
                  @Community Service
                  Certified Qt Specialist
                  http://www.pthinks.com

                  1 Reply Last reply
                  3

                  • Login

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