Skip to content
  • 0 Votes
    6 Posts
    199 Views
    D

    @SGaist I have QApplication - gui one. ah yes the int main() is just a quick hack/example... there full widget app with buttons running :- )

    Also I got it to work, I ended up getting nested futures, and the path to fix that is .unwrap()>https://doc.qt.io/qt-6/qfuture.html#unwrap
    Seems to work! :D

    Threading and linking to context still seem to be broken tho o.o

  • 0 Votes
    24 Posts
    2k Views
    jsulmJ

    @Dean21 Please show your current code if something does not work...

  • 0 Votes
    16 Posts
    1k Views
    P

    @kshegunov
    That seems like a great resource! I will take a look.

  • 0 Votes
    5 Posts
    922 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
    4 Posts
    1k Views
    S

    @VRonin
    Hi, thanks VRonin for the reply. Turns out the problem was to do with the library of FFTW that I used.

    I used separate threads to run functions from that library, which apparently are not thread safe. However, even with mutex locks they still wouldn't work. Back to the drawing board.

    Thanks.

  • 0 Votes
    22 Posts
    18k Views
    Cleiton BuenoC

    I agree, this while() was bothering me.

    I'm using a _timer with QTimer where start() by clicking, I get the Socket data with onReadyRead() process met _timer.stop() but emito sign for the status, seems to be working well.

    But I accept suggestions for improvement, but I removed the loop while()

  • 0 Votes
    4 Posts
    2k Views
    kshegunovK

    @ktwolff

    I placed an exit in my code debugging something and I was curious...

    Well that's the reason for getting the warnings, as exit is really notorious way to quit the application. Long story - short, one shouldn't use it, save for exceptional circumstances.

    Kind regards.

  • 0 Votes
    5 Posts
    1k Views
    Q

    Thanks. I used your code to construct the thing below. It looks not so hot but work just how I need.

    // call this function to start void MainWindow::on_btn_iter_clicked() { maxIter = 5; s = fieldSizeI / threadsAmount; NewIteration(); } void MainWindow::NewIteration() { std::vector<QFutureWatcher<void> *> watchers (threadsAmount); for (size_t i = 0; i < threadsAmount; ++i) { watchers[i] = new QFutureWatcher<void>; connect (watchers[i], SIGNAL (finished()), this, SLOT (S())); } typedef std::vector<QFuture<void> > futures (threadsAmount); for (size_t i = 0; i < threadsAmount; ++i) { futures[i] = QtConcurrent::run(field, &CA_Field::PerformIteration, i*s, (i+1)*s ); watchers[i]->setFuture(futures[i]); } } void MainWindow::S() { ++workCounter; if (workCounter == threadsAmount) { field->AdoptNewState(); workCounter = 0; (--maxIter != 0) ? NewIteration() : UpdateHexMap(); } }