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



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



  • 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".



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



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



  • 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



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



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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.