how can i use Qtimer in gui application with some thread at background?
plz give me an example
how can i use Qtimer in gui application with some thread at background?
plz give me an example
What would you like to achieve in detail?
This is generally bad idea, specially when its asked by a newbie.how can i use Qtimer in gui application with some thread at background?
You probably don't need a thread.
How to use a QTimer.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
well... let me explain the situsatuion... for example i have 100 links. im trying to download each of them with an Qhttp object..
for(link1 to link100)
{
.
.
.
QHttp myHttp = new QHttp(some host);
myHttp.get(some path)
}
till here.. ok?
as u know Qhttp inhertis from Qobject and also Qobject inherits from Qthread so, each instance of Qhttp is a thread by itself... thus the multithreading part is done... is it right?
now i need to make some delay between my requests.. for example 5 seconde.... i add this code to the above code....
for(link1 to link100)
{
.
.
.
QHttp myHttp = new QHttp(some host);
myHttp.get(some path)
QTimer timer;
connect(timer,SIGNAL(timeout()),this,SLOT(someslot ()))
timer.start(5000);
}
but it does not work....
is it clear? if not i can paste my code here.. thanks
so u r right... i made a mistake ... QThread inherits Qobject...
am i wrong? i mean each instance of QHttp isnt a thread by it self?
k.qasempour, the question of the foundations of C++ : what happens with timer at line 11 ?
Qt Code:
for(link1 to link100) { . . . myHttp.get(some path) QTimer timer; connect(timer,SIGNAL(timeout()),this,SLOT(someslot ())) timer.start(5000); }To copy to clipboard, switch view to plain text mode
k.qasempour (11th July 2012)
i know what u mean... but now my question is
each instance of QHttp isnt a thread by it self?
You tell us!each instance of QHttp isnt a thread by it self?
QHttp
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
As far as it is concerned with this particular post, I solve my own problem using single shots. let's say you need to execute a slot two seconds after:
QTimer::singleshot(2000, this, SLOT(slotname()));
I used singleshot inside most of my objects in a project. if you still have problems with it, I can check it out for further details.
and, singleshot or your QTimer.start do not delay the execution of the instruction below them. each timers as soon as called, will be run as a seperate thread. it's like a parent process creating a child of his own using fork() in c.![]()
it does not work again....
here is my code... whats the problem?
QTimer::singleShot(2000, this, SLOT(fake()));
void MainWindow::fake()
{
int a;
a++;
}
This code does not do anything so how do you know it doesn't work?
Bookmarks