comments on QProgress bar example
-
Is there somebody on this forum who actually used QT example of QProgress Bar ?
Could such person help me to analyze the code ?
( Yes it works, no need top analyze that...)
I am posting it as I find the comments not helping to analyze the code to find what exactly is the purpose of it .
I though that comments like these , in professional example , are about kindergarten grade.int TEST = 0 ; /// set TEST to zero
const int iterations = 100; // Prepare the vector. QVector<int> vector; for (int i = 0; i < iterations; ++i) vector.append(i); // Create a progress dialog. QProgressDialog dialog; dialog.setLabelText(QString("Progressing using %1 thread(s)...").arg(QThread::idealThreadCount())); // Create a QFutureWatcher and connect signals and slots. QFutureWatcher<void> futureWatcher; QObject::connect(&futureWatcher, &QFutureWatcher<void>::finished, &dialog, &QProgressDialog::reset); QObject::connect(&dialog, &QProgressDialog::canceled, &futureWatcher, &QFutureWatcher<void>::cancel); QObject::connect(&futureWatcher, &QFutureWatcher<void>::progressRangeChanged, &dialog, &QProgressDialog::setRange); QObject::connect(&futureWatcher, &QFutureWatcher<void>::progressValueChanged, &dialog, &QProgressDialog::setValue); // Our function to compute // this is a dummy std::function<void(int&)> spin = [](int &iteration) { const int work = 1000 * 1000 * 40*5; volatile int v = 0; for (int j = 0; j < work; ++j) ++v; qDebug() << "iteration" << iteration << "in thread" << QThread::currentThreadId(); }; // Start the computation. futureWatcher.setFuture(QtConcurrent::map(vector, spin)); // Display the dialog and start the event loop. dialog.exec(); futureWatcher.waitForFinished(); // Query the future to check if was canceled. qDebug() << "Canceled?" << futureWatcher.future().isCanceled();
-
Is there somebody on this forum who actually used QT example of QProgress Bar ?
Could such person help me to analyze the code ?
( Yes it works, no need top analyze that...)
I am posting it as I find the comments not helping to analyze the code to find what exactly is the purpose of it .
I though that comments like these , in professional example , are about kindergarten grade.int TEST = 0 ; /// set TEST to zero
const int iterations = 100; // Prepare the vector. QVector<int> vector; for (int i = 0; i < iterations; ++i) vector.append(i); // Create a progress dialog. QProgressDialog dialog; dialog.setLabelText(QString("Progressing using %1 thread(s)...").arg(QThread::idealThreadCount())); // Create a QFutureWatcher and connect signals and slots. QFutureWatcher<void> futureWatcher; QObject::connect(&futureWatcher, &QFutureWatcher<void>::finished, &dialog, &QProgressDialog::reset); QObject::connect(&dialog, &QProgressDialog::canceled, &futureWatcher, &QFutureWatcher<void>::cancel); QObject::connect(&futureWatcher, &QFutureWatcher<void>::progressRangeChanged, &dialog, &QProgressDialog::setRange); QObject::connect(&futureWatcher, &QFutureWatcher<void>::progressValueChanged, &dialog, &QProgressDialog::setValue); // Our function to compute // this is a dummy std::function<void(int&)> spin = [](int &iteration) { const int work = 1000 * 1000 * 40*5; volatile int v = 0; for (int j = 0; j < work; ++j) ++v; qDebug() << "iteration" << iteration << "in thread" << QThread::currentThreadId(); }; // Start the computation. futureWatcher.setFuture(QtConcurrent::map(vector, spin)); // Display the dialog and start the event loop. dialog.exec(); futureWatcher.waitForFinished(); // Query the future to check if was canceled. qDebug() << "Canceled?" << futureWatcher.future().isCanceled();
@AnneRanch said in comments on QProgress bar example:
I though that comments like these , in professional example , are about kindergarten grade.
Maybe you mention what exactly you dont understand?!
The example is pretty simple, so what comments do you expect? They describe what is happening in the next line(s).as I find the comments not helping to analyze the code to find what exactly is the purpose of it .
They do.
And from looking at the code you can see/guess/assume what every single line does, even you if have never used Qt before... from the naming, the usage and these few comments, which you are claiming to be Kindergarten ;-)
If you think there are more comments than code needed, in an example with the solely purpose of showing howQProgressBar
in combination with someQtConcurrent
elements works and how you could use it (besides reading the documentation), go ahead. Provide some "more useful" comments and contribute...The comments are actually even better than I would have expected and more than needed.
Like here ¯\_(ツ)_/¯
// Create a progress dialog.
QProgressDialog dialog;or here
// Display the dialog and start the event loop.
dialog.exec();and here (comment on
qDebug
output)// Query the future to check if was canceled.
qDebug() << "Canceled?" << futureWatcher.future().isCanceled();If you ditch those and there would be no comments at all, this post would look like "Why are there no comments on this example?".
People are always complaining...