QTimer help needed
-
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.
-
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 ...
-
In function "Metodas" :
- 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.
- 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. -
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!
-
But parametras += 1 ====== parametras + 1 and when qtimer is initialized parametras keep growing until i close program... or i misunderstood something?
-
Sometime, I prefer not answering than being rude.
-
sorry for me... i am newbie at qt and trying to do this work..
-
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);
@ -
Very big thanks to you!!!! You are genius !
-
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? -
ty!!!
-
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.
-
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.