• <tfoot id='2YGsr'></tfoot>
    <i id='2YGsr'><tr id='2YGsr'><dt id='2YGsr'><q id='2YGsr'><span id='2YGsr'><b id='2YGsr'><form id='2YGsr'><ins id='2YGsr'></ins><ul id='2YGsr'></ul><sub id='2YGsr'></sub></form><legend id='2YGsr'></legend><bdo id='2YGsr'><pre id='2YGsr'><center id='2YGsr'></center></pre></bdo></b><th id='2YGsr'></th></span></q></dt></tr></i><div id='2YGsr'><tfoot id='2YGsr'></tfoot><dl id='2YGsr'><fieldset id='2YGsr'></fieldset></dl></div>
    <legend id='2YGsr'><style id='2YGsr'><dir id='2YGsr'><q id='2YGsr'></q></dir></style></legend>

          <bdo id='2YGsr'></bdo><ul id='2YGsr'></ul>

        <small id='2YGsr'></small><noframes id='2YGsr'>

        QtConcurrent 与成员函数

        时间:2023-09-26

          <bdo id='I5b1L'></bdo><ul id='I5b1L'></ul>
          • <legend id='I5b1L'><style id='I5b1L'><dir id='I5b1L'><q id='I5b1L'></q></dir></style></legend>

            1. <tfoot id='I5b1L'></tfoot>
            2. <i id='I5b1L'><tr id='I5b1L'><dt id='I5b1L'><q id='I5b1L'><span id='I5b1L'><b id='I5b1L'><form id='I5b1L'><ins id='I5b1L'></ins><ul id='I5b1L'></ul><sub id='I5b1L'></sub></form><legend id='I5b1L'></legend><bdo id='I5b1L'><pre id='I5b1L'><center id='I5b1L'></center></pre></bdo></b><th id='I5b1L'></th></span></q></dt></tr></i><div id='I5b1L'><tfoot id='I5b1L'></tfoot><dl id='I5b1L'><fieldset id='I5b1L'></fieldset></dl></div>
                <tbody id='I5b1L'></tbody>
                • <small id='I5b1L'></small><noframes id='I5b1L'>

                  本文介绍了QtConcurrent 与成员函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我创建了一个 QFuture,我想用它来并行化对成员函数的调用.更准确地说,我有一个带有 .h 的 solveParallel 类:

                  I create a QFuture that I want to use to parallelize calls to a member function. More precisely, I have a class solveParallel with .h :

                  class solverParallel {
                  public:
                    solverParallelData(Manager* mgr_);
                    virtual ~solverParallel(void);
                  
                    void runCompute(solveModel * model_);
                  
                    bool resultComput();
                  
                  private:
                    Manager *myMgr;
                    QFuture<bool> myFutureCompute;
                  }; 
                  

                  runCompute() 方法正在创建 myFutureCompute 成员..cpp 看起来像

                  where the methode runCompute() is creating the myFutureCompute member. .cpp looks like

                  solveParallel::solveParallel(Manager* mgr_)
                  :m_mgr(mgr_)
                  {
                  }
                  
                  solverParallel::~solverParallel(void){}
                  
                  void solverParallel::runCompute(solveModel* model)
                  {
                    futureComput = QtConcurrent::run(&this->myMgr,&Manager::compute(model));
                  }
                  
                  bool solverParallelData::resultComput()
                  {
                    return m_futureComput.result();
                  }
                  

                  包含都可以.编译失败,上线

                  Include(s) are all right. Compilation fails, on line

                  futureComput = QtConcurrent::run(&this->myMgr,&Manager::compute(model));
                  

                  出现此错误:

                  Error   44  error C2784: 'QFuture<T> QtConcurrent::run(T (__cdecl *)(Param1),const     Arg1 &)' : could not deduce template argument for 'T (__cdecl *)    (Param1)' from 'Manager **'   solverparallel.cpp 31
                  

                  此外,关于同一行代码中&Manager"的鼠标信息:错误:非静态成员引用必须与特定对象相关.

                  In addition, on mouse info for '&Manager' in same line of code stands: Error: a nonstatic member reference must be relative to a specific object.

                  你知道诀窍在哪里吗?感谢和问候.

                  Do you see where is the trick? Thanks and regards.

                  推荐答案

                  来自 官方文档 :

                  QtConcurrent::run() 也接受指向成员函数的指针.这第一个参数必须是常量引用或指向类的实例.在以下情况下通过 const 引用传递很有用调用 const 成员函数;通过指针传递对于调用修改实例的非常量成员函数.

                  QtConcurrent::run() also accepts pointers to member functions. The first argument must be either a const reference or a pointer to an instance of the class. Passing by const reference is useful when calling const member functions; passing by pointer is useful for calling non-const member functions that modify the instance.

                  您正在传递一个指向指针的指针.另请注意,您不能按照自己的方式传递参数,而是作为 run 函数中的额外参数.以下应该有效:

                  You are passing a pointer to a pointer. Also notice that you cannot pass the arguments the way you do, but as extra arguments in the run function. The following should work:

                  futureComput = QtConcurrent::run(this->myMgr,&Manager::compute, model);
                  

                  这篇关于QtConcurrent 与成员函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:c++ 如何优雅地将 c++17 并行执行与计算整数的 for 循环一起使用? 下一篇:使用 openmp &amp; 并行化 for 循环替换 push_back

                  相关文章

                  <i id='53AFK'><tr id='53AFK'><dt id='53AFK'><q id='53AFK'><span id='53AFK'><b id='53AFK'><form id='53AFK'><ins id='53AFK'></ins><ul id='53AFK'></ul><sub id='53AFK'></sub></form><legend id='53AFK'></legend><bdo id='53AFK'><pre id='53AFK'><center id='53AFK'></center></pre></bdo></b><th id='53AFK'></th></span></q></dt></tr></i><div id='53AFK'><tfoot id='53AFK'></tfoot><dl id='53AFK'><fieldset id='53AFK'></fieldset></dl></div>
                  <legend id='53AFK'><style id='53AFK'><dir id='53AFK'><q id='53AFK'></q></dir></style></legend>

                • <tfoot id='53AFK'></tfoot>
                  1. <small id='53AFK'></small><noframes id='53AFK'>

                        <bdo id='53AFK'></bdo><ul id='53AFK'></ul>