Results 1 to 6 of 6

Thread: Pass parameters through QFutureWatcher to finished function

  1. #1
    Join Date
    Jan 2018
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Pass parameters through QFutureWatcher to finished function

    I am trying to move a time consuming part of a function to a concurrent process. I am running into a problem though. There are a lot of parameters passed to this new concurrent function that I need access to after the concurrent processed has finished. Is there a way I can pass certain parameters from the function that setup the QFutureWatcher to the function that is called when finished() fires?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Pass parameters through QFutureWatcher to finished function

    There are a lot of parameters passed to this new concurrent function that I need access to after the concurrent processed has finished.
    Why not pack them in a simple data object like a struct?

    Is there a way I can pass certain parameters from the function that setup the QFutureWatcher to the function that is called when finished() fires?
    At least for me it is not really clear what you are trying to do (not what you are asking about).
    Seems like it could be done simpler, and thus maybe avoid the problem you have in the first place.
    If you could elaborate a bit more, and with some code, it will help better understand what your needs are.
    ==========================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.

  3. #3
    Join Date
    Jan 2018
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Pass parameters through QFutureWatcher to finished function

    Here's what is actually happening:

    1) User clicks a button to start this process
    2) Information is collected from the GUI, a filename is automatically generated
    3) Based on the information from the GUI, hardware collects and writes a data file (This is the time consuming process)
    4) During the hardware process another process could be launched, data from the GUI could be changed, etc...
    5) When the hardware process is complete (finished() fires) I have to process the data file it wrote. I need:
    i) The filename of the data it wrote
    ii) Information on how the hardware was configured for that particular run (Frequency of a laser, power of the laser, etc...)

    Any idea how to launch the concurrent process and then recover the parameters used for that run?

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Pass parameters through QFutureWatcher to finished function

    Any idea how to launch the concurrent process and then recover the parameters used for that run?
    I fail to see what the problem is.
    Synchronizing data between threads (you are talking about a thread here, not a process) is only needed if more than one threads needs to access the data at the "same time".
    It doesn't sound like this is the case for you.
    Again, I would pack the information in a struct and read from it.

    Maybe some code would help to understand better what is the problem you are having.
    ==========================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.

  5. #5
    Join Date
    Jan 2018
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Pass parameters through QFutureWatcher to finished function

    After the concurrent thread completes, then the parameters used are destroyed right?

    The filename created was based on a date/time, the user could have changed values in the GUI and launched a second (Or third, or fourth) thread.

    So how do I recover the values used to launch THAT concurrent thread? Even if I stuck them all together in a struct, they would still be deleted when the thread completed.

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Pass parameters through QFutureWatcher to finished function

    Even if I stuck them all together in a struct, they would still be deleted when the thread completed.
    Why do you think that? If you pack them into a struct, you simply save a copy of that struct in the calling side of your code before you send them off to the thread.

    If you don't want to do that, you could customize a QThread instance so that it emits its own finished() signal that includes a copy of the arguments.

    Or if you derive from QThread and give your custom QThread class getter / setter methods to retrieve and set the parameters. If you connect a slot to the thread's finished() signal, you can use QObject::sender() in your slot to retrieve the pointer to the QThread that sent the signal and retrieve your parameters through that pointer. The QThread won't be deleted until all slots connected to its signals complete.

    There are probably other ways to accomplish your goal; these are just three of the possible solutions.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 1
    Last Post: 29th June 2015, 10:27
  2. QFutureWatcher doesn't get finished signal
    By Mobility in forum Newbie
    Replies: 3
    Last Post: 20th September 2012, 09:25
  3. QFutureWatcher finished() signal not working
    By DiamonDogX in forum Qt Programming
    Replies: 13
    Last Post: 25th October 2011, 18:27
  4. QFutureWatcher finished without even starting a QFuture...
    By Zweistein in forum Qt Programming
    Replies: 0
    Last Post: 22nd September 2011, 14:30
  5. Replies: 3
    Last Post: 13th July 2011, 08:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.