Skip to content
  • 0 Votes
    3 Posts
    256 Views
    M

    @jsulm Sorry, it's my fault.
    I write wrong parameters at lamda function :(;;;

  • 0 Votes
    2 Posts
    268 Views
    SGaistS

    Hi,

    If you want to use a member function, the array you pass to the map method must contain items of that class.

  • QtConcurrent mapped crashes

    Unsolved General and Desktop
    16
    0 Votes
    16 Posts
    1k Views
    SGaistS

    Hi,

    You create a QImage out of an OpenCV Mat object. The constructor you use for that explicitly does not copy the data from the Mat object. This is what the warning is all about. It is your job to ensure that the Mat object lifetime is longer than the one of of your QImage.

    Or you should explicitly trigger a copy of the QImage object when adding it to your array.

    What happens is that when you do your concurrent call is that Mat object that used went out of scope and thus the QImage internal structure is now pointing to invalid data.

  • 0 Votes
    5 Posts
    923 Views
    CybeXC

    @VRonin
    Quite right - infact 101% correct.

    However, and you can correct me if I am wrong, but these mapped functions can be used for more than just transforming the datatype into another datatype. It does not always need to be 'instance based'. Let me explain what I mean (and what my thought process is)

    In Java (lang level 8), there is the introduction of the Stream API with a bunch of additional features such as lambdas, etc. One particularly useful example is something like

    List<SomeClass> list = ... list.stream().map(o -> o.someMember).filter(o -> o.value < 2).collect(Collectors.asList());

    Now this simply takes an object (of type List), and runs a mapping functions (returning a stream object) and running a filter function on it (returning another stream object) followed by collecting all objects into a list.

    Now, my intention, specifically in this case is to utilize the filter & map functions similarly, but due to its design (QtConcurrent functions), I am breaking these functions up with signals (and slots) everywhere.

    This isn't part of the question, but for my own curiosity, if one had to mimik functions like this above, is there a...shorter way of doing the same thing rather than

    QFuture<SomeStruct> future = ... QFutureWatcher<SomeStruct> ... connect( //futurewatcher signal started with whatever) connect( //futurewatcher signal finished with whatever) QFutureWatcher::setFuture(future) ...

    just for one part of the function (i.e. mapping or filter)

  • 0 Votes
    9 Posts
    10k Views
    McLionM

    I'd like to add:

    Specially if the Watcher needs to be used multiple times it's important to disconnect it after use:

    disconnect(FormatWatcher, SIGNAL(finished()), this, SLOT(FinishedFormat())); // disconnect former slot used with watcher