Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

how we can create 2 second delay or wait in qml?



  • i don't want use import QtTest 1.0,
    i want before that my method executes ,it wait a little and start to execute,thanks for reply. in another way can anyone guide me



  • You can't use a Timer?



  • @t3685 said:

    You can't use a Timer?

    oh,you are right thanks for reply............



  • Sometimes things are so obvious we can't even see them😃



  • with guidance my dear friend @t3685
    i create a some delay function

    function delay(duration) { // In milliseconds
        var timeStart = new Date().getTime();
    
        while (new Date().getTime() - timeStart < duration) {
            // Do nothing
        }
    
        // Duration has passed
    }
    

    or another way

    function delay(delayTime) {
        timer = new Timer();
        timer.interval = delayTime;
        timer.repeat = false;
        timer.start();
    }
    


  • Are you looking for something like this?

    Timer {
        id: timer
        running: false
        repeat: false
    
        property var callback
    
        onTriggered: callback()
    }
    
    function setTimeout(callback, delay)
    {
        if (timer.running) {
            console.error("nested calls to setTimeout are not supported!");
            return;
        }
        timer.callback = callback;
        // note: an interval of 0 is directly triggered, so add a little padding
        timer.interval = delay + 1;
        timer.running = true;
    }


  • my problem is solved before thanks very much


Log in to reply