Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Delay function
Qt 6.11 is out! See what's new in the release blog

Delay function

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 2 Posters 868 Views 1 Watching
  • 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.
  • S Offline
    S Offline
    saivineeth
    wrote on last edited by saivineeth
    #1

    Hi
    I was creating a sine wave by using canvas how to add delay function
    Can someone help me to solve it how to add how to us

    import QtQuick 2.9
    import QtQuick.Window 2.15
    
    Window {
    
        function timer() {
            return Qt.createQmlObject("import QtQuick 2.0; Timer {}", root);
        }
    
        id:screen
        visible:true
        height: 1080
        width: 1920
        title: qsTr("SineWave")
        Rectangle{
            height:parent.height
            width:parent.width
            Timer {
                id: timer
            }
    
            function delay(delayTime, cb) {
                timer.interval = delayTime;
                timer.repeat = false;
                timer.triggered.connect(cb);
                timer.start();
            }
            Canvas{
                id:canvas
                anchors.fill:parent
                onPaint: {
                    var ctx = getContext("2d");
                    var cw = parent.width;
                    var ch = parent.height;
                    var  cx = cw, cy = ch/2;
                    var w= width;
                    var h= height;
                    ctx.lineWidth= 4;
                    ctx.clearRect(0, 0, cw, ch);
                    ctx.beginPath();
                    ctx.moveTo(0, cy);
    
                    for(var x=0;x<1921;x++){
                        var y = Math.sin(x/305);
                        ctx.lineTo(x, cy+(y*400));//now you add delay of 1sec
                        console.log(y)
                    }//from here the sine wave is plotted from left to right clean the screen with small from left to right
    
    
                    ctx.stroke();
                    showMaximized(Window)
                }
            }
        }
    }
    
    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      What kind of delay? Is Qt.callLater() enough?

      (Z(:^

      S 1 Reply Last reply
      0
      • sierdzioS sierdzio

        What kind of delay? Is Qt.callLater() enough?

        S Offline
        S Offline
        saivineeth
        wrote on last edited by
        #3

        @sierdzio no i am creating wave in qml

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          OK and you want to delay the painting?

          Or you ask how to mathematically delay the sine so it starts at a different value?

          (Z(:^

          S 1 Reply Last reply
          0
          • sierdzioS sierdzio

            OK and you want to delay the painting?

            Or you ask how to mathematically delay the sine so it starts at a different value?

            S Offline
            S Offline
            saivineeth
            wrote on last edited by
            #5

            @sierdzio once check the code and tell me how to solve it i add timer where i need to call it
            I don't know about timmer i was trying it can u help me out
            I need output like i need a delay 1 millisecond between 1 plotting to another plotting

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              Just throw in await sleep(1); at the end of your JS code, then.

              (Z(:^

              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