I'm beginner learning Qt, and trying to understand a Qt provided example for download operation. In downloadmanager.cpp, a member function is the following:
void DownloadManager::append(const QUrl &url)
{
if (downloadQueue.isEmpty())
QTimer::singleShot(0, this, SLOT(startNextDownload()));
downloadQueue.enqueue(url);
++totalCount;
}
- I'm confused to why, if
downloadQueue
is empty, it will need to activate thestartNextDownload()
before adding the url. (note that:startNextDownload()
ends the program if thedownloadQueue
is empty) - I'm unsure why:
QTimer::signleShot(x, y, z)
has been used at all. As I understand it to be, a timer that activates the slot with delay of 0 millisecond. - I could not figure out from looking at Qt Assistant whether singleShot is a one time setup for repeated activation to the slot at given millisecond interval or whether it is one time
Clarification:
I'm a beginner and in examples like:
statement1;
statement2;
I'm used to seeing statement1
running and finishing before moving on to working on statement2
. But trying to learn Qt and reading the given example, I see the SLOT(startNextDownload())
being activated after downloadQueue.enqueue(url);
has taken place. I am trying to understand why does this work.