Is QtConcurrent::run a mature feature, new or obsolete?



  • Hi,

    I am having a difficult time using the embedded Qt help to figure out how to use QtConcurrent::run. No matter what I've tried I still get the error "no matching function for call to 'run(...". It makes me wonder if QtConcurrent::run is too new or already obsolete (I'm sure it's neither).

    I want to present a Qt page with videos (controlled outside of Qt). Currently it takes more than a second to start a video. It would be great if the Qt elements were rendered independently of the video starting so that they would show up even before the video. So I thought it would be a great application of QtConcurrent::run. I was going to use it to start the video. But so far I've gotten no where.

    The on line help would make me believe all I need to do to use QtConcurrent::run is to add "#include <QtCore>". But posts here and there would indicate I also need to add "#include <QtConcurrentRun>". Any comments on this? Perhaps I am still missing another include?

    Also, I am working off the example 2 of QtConcurrent::run on this web page in the nokia.com domain:
    http://developer.qt.nokia.com/doc/qt-4.8/thread-basics.html
    Here you can find an example of a call to QtConcurrent::run. But notice that the first argument is simply the function name hello. There are numerous postings which contradict this. People have been stating that you should pass QtConcurrent::run a pointer to the function! Is that true? Is the nokia example wrong?

    So here is the offending call in my code:
    @ QtConcurrent::run(&gui_RTC::playVideoReal, sFileName, x, y, h, w, volume);@

    Here is the error from Qt:
    @gui_rtc.cpp:442: error: no matching function for call to 'run(void (gui_RTC::*)(QString, int, int, int, int, int), QString&, int&, int&, int&, int&, int&)'@

    Here is the definition of the function I am trying to run independently of the main Qt application:
    @ void playVideoReal(QString, int, int, int, int, int);@

    Hopefully someone will see my mistake and post a followup.

    -thanks



  • The docs are quite clear on this:

    bq. The <QtConcurrentRun> header provides a way to run a function in a separate thread.

    And yes, that API is considered mature.

    It looks like you're trying to call a member function of a class in the concurrent run. If so, you need an additional argument denoting the actual object:

    @
    // somewhere else
    gui_RTC *gui = new gui_RTC(this);

    QtConcurrent::run(gui, &gui_RTC::playVideoReal, sFileName, x, y, h, w, volume);
    @

    Have a look at the "using member functions":/doc/qt-4.8/qtconcurrentrun.html#using-member-functions section of the docs for the details.



  • Thank you Volker for your help. I am sorry if these are not good questions. Or even if they are already answered else where. Truth is there is hardly any time in this economy to do a decent job any more. Most businesses are willing to gamble on out sourcing projects assuming some will fail. The reasoning is that the cost is so low failure is acceptable. It's all very frustrating and the cause for me to come here hoping for quick guidance when what I have read has failed.

    I tried what you suggested and can not get it to work. I think there are other (what I consider) subtle circumstances at work. For instance I realized about about an hour into trying your suggestions that the function I was trying to run concurrently is in the SLOTS section of the header file. I am not sure how that effects the above code. I moved it (with the expectation it will break many our our video playing features), but still could not get the code to compile.



  • Methods declared under slots section can be used like ordinary methods. In fact, from C++'s point of view they are not distinguishable from non-slot methods. It's just needed for the moc run, to have it generate the necessary glue code for signal/slot connections. So this does not cure the errors.

    Maybe you can make a simple test project, just the necessary code to reproduce the error, a method with just a dummy implementation. Without some code snippets, it's hard to tell what's going wrong here.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.