Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. weird behavior from future and promise
Forum Updated to NodeBB v4.3 + New Features

weird behavior from future and promise

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 151 Views 1 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
    Alireza Nikpay
    wrote on last edited by
    #1

    Hi
    I saw a weird behavior in the project (at least weird to me!) when QProgressBar::setValue(int) used!
    The scenario is like this:
    There is button which when clicked it would get a file from a device using API functions and there is a promise to set and a future to get for progress bar in the GUI to show the progress. easy enough I guess, ha?!
    We have 3 threads, thread1 is the main thread, so the SLOT to the button and showing the progress bar is in this thread, notice that just showing not updating.
    In thread2 we will run that function in the API which will get the file from the device. Process is in a raw-for-loop which will get only 2048 Byte data each time, so we need that for-loop and each time that we get the 2048 Byte, promise will be set with the size of data (0, 2048, 4096, 6144, etc). When we get the file completely there is a SIGNAL which I will emit, that signal is for creating and showing the QProgressBar not for updating it.
    Thread3 will update the QProgressBar , every iteration in the loop of getting file, I am emitting a SIGNAL, the SLOT for that is a function like this:

    void MainWindows::updateProgressBar(int value)
    {
      qDebug() << "Value: " << value;
      progressBar->setValue(value);
    }
    

    which is in the Thread1, so the SIGNAL is from MyClass and SLOT is in MainWindows.
    And yes I know I can use this:
    connect(myClassObj, SIGNAL(updateProgressNotifier(int)), progressBar, SLOT(setValue(int)));
    So the weird part is: when I use the above code the program runs very fast, like 5x, and the program will crash in API!, but when I just comment
    progressBar->setValue(value);
    the qDebug() will get run slowly!
    I think the slow run is the accurate one, because speed of the device is not enough to give me that speed for the progress! and THAT'S the weird PART.
    If it is any problem in my question, please just tell me to correct it and improve it (and I know there is a lot of problems).
    Thanks.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Please don't post the same question in multiple sub-forum. One is enough.

      Duplicate

      Closing this one.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

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