Combine QtConcurrent call
-
Good idea but it think it can't be compiled (I did not test).
std::functionis a template and needs to be fully qualified. So you either:- specify the template parameters of the wrapper member fixing what function
searchmust be - make the wrapper a template but then you can't store different specialisations of the same template in the same container
I still think polymorphism is not just the right answer here but the only acceptable one
@Mr-Gisa
can you give us a rough example of what "collection" and "objects" means in your case?@VRonin said in Combine QtConcurrent call:
Good idea but it think it can't be compiled (I did not test).
std::functionis a template and needs to be fully qualified. So you either:- specify the template parameters of the wrapper member fixing what function
searchmust be - make the wrapper a template but then you can't store different specialisations of the same template in the same container
I still think polymorphism is not just the right answer here but the only acceptable one
@Mr-Gisa
can you give us a rough example of what "collection" and "objects" means in your case?Well, OP didn't specify whether the methods have different signatures. But even if they have, you may be able to use
std::function<QString()>and provide the needed parameter in the bind call, like so:
auto myFunction = std::bind(&MyClass::MyMethod1,this,parameter1,parameter2,parameter3);Assuming MyMethod returns a string, that should work.
- specify the template parameters of the wrapper member fixing what function
-
@VRonin said in Combine QtConcurrent call:
Good idea but it think it can't be compiled (I did not test).
std::functionis a template and needs to be fully qualified. So you either:- specify the template parameters of the wrapper member fixing what function
searchmust be - make the wrapper a template but then you can't store different specialisations of the same template in the same container
I still think polymorphism is not just the right answer here but the only acceptable one
@Mr-Gisa
can you give us a rough example of what "collection" and "objects" means in your case?Well, OP didn't specify whether the methods have different signatures. But even if they have, you may be able to use
std::function<QString()>and provide the needed parameter in the bind call, like so:
auto myFunction = std::bind(&MyClass::MyMethod1,this,parameter1,parameter2,parameter3);Assuming MyMethod returns a string, that should work.
@Asperamanca said in Combine QtConcurrent call:
you may be able to use
std::function<QString()>Variadic template specialisation is just too much for my little brain to process. I'm still not convinced but certainly not smart enough to say it's defenetly not going to work
- specify the template parameters of the wrapper member fixing what function
-
@Asperamanca said in Combine QtConcurrent call:
you may be able to use
std::function<QString()>Variadic template specialisation is just too much for my little brain to process. I'm still not convinced but certainly not smart enough to say it's defenetly not going to work
@VRonin
I think both approaches would work in this case. If OP says he has different classes, but each has a "Search" method, creating a "Searchable" interface and making the Search method virtual sounds like a good approach. -
@Asperamanca @VRonin I think that the best way for me to explain in showing some code. This is an example of what I'm planning to do.
And beforehand: I put the classes instances in a container cause each one of those classes will be a plugin and will be loaded using
QPluginLoaderlater on, so in order to minimize the problem I just put it in a kind of container.Here you can see the example code: https://pastebin.com/raw/7BwgppwQ
As I will be processing heavy operations (like http requests, parsing, etc) in each
searchmethod I wanted to call it asynchronously and so I though thatQt Concurrentwould help me with that.
And another thing: as I want the result of all the classes into a singleQListI put aQStringinside theResultstruct to identify the site that it has been found (maybe I could use the pointer likeQModelIndexdoes?).So yeah, that is what I want to do.
-
The argument is just a string that will be used as query, this is just a prototype. But it's just a string.
Also keep in mind that accessing the values in the container before the end of the concurrent process is a race condition.
I want to create a kind of real time searcher, like when the user type a query it will async call all the search method from all the websites and in real time while it's finding the results I want to put all the results in a list view.
-
The argument is just a string that will be used as query, this is just a prototype. But it's just a string.
Also keep in mind that accessing the values in the container before the end of the concurrent process is a race condition.
I want to create a kind of real time searcher, like when the user type a query it will async call all the search method from all the websites and in real time while it's finding the results I want to put all the results in a list view.
-
@VRonin Is it too early to say that I'm falling in love with you even without calling you out for dinner? haha, just kidding, you rock!!!
Thank you very much.
Just one last question:
Probably I will create a custom model and delegate to display the items so I was wondering, if I want to create a kind of status for eachResultand update them in real time on the view I have to use a kind of struct inside theResultwith the status types and use signals and slots to update that right? -
@VRonin Is it too early to say that I'm falling in love with you even without calling you out for dinner? haha, just kidding, you rock!!!
Thank you very much.
Just one last question:
Probably I will create a custom model and delegate to display the items so I was wondering, if I want to create a kind of status for eachResultand update them in real time on the view I have to use a kind of struct inside theResultwith the status types and use signals and slots to update that right?@Mr-Gisa said in Combine QtConcurrent call:
update them in real time on the view
You'd have to store the result inside the
ISearchableclass and then useQFutureWatcher::resultAt, it's a bit more involved@Mr-Gisa said in Combine QtConcurrent call:
Is it too early to say that I'm falling in love with you even without calling you out for dinner?
Qt Forum is the new Tinder
-
@Mr-Gisa said in Combine QtConcurrent call:
update them in real time on the view
You'd have to store the result inside the
ISearchableclass and then useQFutureWatcher::resultAt, it's a bit more involved@Mr-Gisa said in Combine QtConcurrent call:
Is it too early to say that I'm falling in love with you even without calling you out for dinner?
Qt Forum is the new Tinder
You'd have to store the result inside the ISearchable class and then use QFutureWatcher::resultAt, it's a bit more involved.
I would love some help with that, for real.
I was reading the docs and I saw that Qt has
QFutureSynchronizerthat syncs multipleQFuture, what is the difference between what we are doing here andQFutureSynchronizer?I changed the sleep time of
SiteAin order to check what happens and it freezes even ifSiteBfinished already its results. I really wanted that to display to the list view right when the results are ready.