• <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 与成员函数

        QtConcurrent with member function(QtConcurrent 与成员函数)

          <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 与成员函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Constructor initialization Vs assignment(构造函数初始化 Vs 赋值)
                  Is a `=default` move constructor equivalent to a member-wise move constructor?(`=default` 移动构造函数是否等同于成员移动构造函数?)
                  Has the new C++11 member initialization feature at declaration made initialization lists obsolete?(声明时新的 C++11 成员初始化功能是否使初始化列表过时了?)
                  Order of constructor call in virtual inheritance(虚继承中构造函数调用的顺序)
                  How to use sfinae for selecting constructors?(如何使用 sfinae 选择构造函数?)
                  Initializing a union with a non-trivial constructor(使用非平凡的构造函数初始化联合)
                    <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>
                      <tbody id='53AFK'></tbody>
                    1. <small id='53AFK'></small><noframes id='53AFK'>

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