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 help needed

QTimer help needed

Scheduled Pinned Locked Moved General and Desktop
20 Posts 6 Posters 8.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.
  • V Offline
    V Offline
    vinb
    wrote on last edited by
    #6

    Do you read the suggestions people gave you?
    florent.revelut and ZapB (and me in an other topic) gave you a solution for your problem, so why dont you try that first?
    If you, for some reason, want to stick with the timer idea, then you use the timeout signal as you did.

    nb. try a little with the "parametras". +1 is not that much on a large screen.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      audrensitas
      wrote on last edited by
      #7

      First of all, thanks for advices, but teacher requires QTimer :)... That is why i am using it.

      try a little with the “parametras”. +1 is not that much on a large screen. <- i didn't understand this sentence..

      You all gave me useful advices, but i still don't understand how to move my duck on the screen.. how to make it moving ...

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vinb
        wrote on last edited by
        #8

        In function "Metodas" :

        1. You set "parametras" to parametras += 1. (line 3) But you dont use a loop to increase "parametras". So "parametras" = always 1 in your function, because in your main you set it to 0 and in the function you set it to 1.
        2. In line 9 you "move" the label to (int x = "parametras" = 1, int y = 20).

        With other words,
        You put the label at a "fixed" coordinate when your timer is finished. After that you dont do anything, so it stays that way.
        Make a loop with an incement of "parametras". And keep in mind that if my screen is 2000 pixels width i am not really see an increment of 1 pixel.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          audrensitas
          wrote on last edited by
          #9

          Thanks for reply!!!

          But when i execute program object is not moving, just objects are generating i wonder how to make just one object and make it moving ? ? ?

          Cheers!

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vinb
            wrote on last edited by
            #10

            Did you read my reply?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              audrensitas
              wrote on last edited by
              #11

              But parametras += 1 ====== parametras + 1 and when qtimer is initialized parametras keep growing until i close program... or i misunderstood something?

              1 Reply Last reply
              0
              • F Offline
                F Offline
                florent.revelut
                wrote on last edited by
                #12

                Sometime, I prefer not answering than being rude.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  audrensitas
                  wrote on last edited by
                  #13

                  sorry for me... i am newbie at qt and trying to do this work..

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    vinb
                    wrote on last edited by
                    #14

                    Sorry, i was thinking about a singleshot :).
                    I see that you create a new label in your function "Metodas", this means that you always make a new label when your timer finishes, I dont think that that is what you want.

                    Just create the timer and label in your constructor and move it in your function.

                    here is a little example wich works:

                    In ".h":
                    @
                    int xas;
                    int yas;
                    QLabel *l;
                    @

                    In constructor:
                    @
                    l = new QLabel(this);
                    l->setText("Move Please?");
                    l->setGeometry(0,0,200,20);
                    l->show();
                    xas = 1;
                    yas = 1;
                    QTimer *t = new QTimer(this);
                    connect(t,SIGNAL(timeout()),this,SLOT(Metodas()));
                    t->setInterval(1/30);
                    t->start(50);
                    @
                    in metodas:
                    @
                    xas +=1;
                    yas +=1;
                    l->move(xas,yas);
                    @

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      audrensitas
                      wrote on last edited by
                      #15

                      Very big thanks to you!!!! You are genius !

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        audrensitas
                        wrote on last edited by
                        #16

                        And the last question... :) Is there a possibility to make y axis random ? I need that duck would be moving x axis as you mentioned, but i need that it would appear in random place on y axis .
                        I have tried
                        @ yas = rand()+240; @
                        but the duck appears in the value of y axis = 240. Is there a way to make it random?

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          giesbert
                          wrote on last edited by
                          #17

                          Hi audrensitas,

                          call
                          @
                          srand(time(0));
                          @

                          once (e.g. in main);

                          then call

                          @
                          yas = rand() % 240;
                          @

                          Nokia Certified Qt Specialist.
                          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            audrensitas
                            wrote on last edited by
                            #18

                            ty!!!

                            1 Reply Last reply
                            0
                            • T Offline
                              T Offline
                              tobias.hunger
                              wrote on last edited by
                              #19

                              audrensitas: You do not believe in reading, do you? It is really easy to pick up example code on google when you already know the function name!

                              You know that the idea behind homeworks is that the pupil learns something? That includes how to find background information. Bugging people on the internet with really basic questions is not the best way to accomplish that in my opinion.

                              1 Reply Last reply
                              0
                              • Z Offline
                                Z Offline
                                ZapB
                                wrote on last edited by
                                #20

                                And perhaps even more important is then the emerging understanding from reading and digesting such examples. This then allows you to apply techniques and particular building blocks in other situations. Learning should also be fun. Do not be afraid to experiment on your own.

                                Nokia Certified Qt Specialist
                                Interested in hearing about Qt related work

                                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