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. comments on QProgress bar example
Forum Updated to NodeBB v4.3 + New Features

comments on QProgress bar example

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 229 Views 2 Watching
  • 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1

    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();
    
    
    Pl45m4P 1 Reply Last reply
    0
    • A Anonymous_Banned275

      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();
      
      
      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @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 how QProgressBar in combination with some QtConcurrent 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...


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      3

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved