【问题标题】:QtConcurrent::run() calling another class methodQtConcurrent::run() 调用另一个类方法
【发布时间】:2018-08-21 17:37:53
【问题描述】:

我正在尝试使用 QTConcurrent 类来异步启动一些任务,但我遇到了一些错误:

这是我的代码:

class A {
  public:
  void method1();
};
class B {
 std::unique_ptr<A> ptr;
 public:
  void method2() {
     QtConcurrent::run(&this->ptr, &A::method1);
  }
}

我得到编译错误。

谁能告诉我正确的语法是什么?

提前致谢和问候

【问题讨论】:

  • B 没有名为 _xdmService 的成员。名称 PttpXdmService 未声明。难怪你会在这个例子中遇到编译错误。

标签: c++11 qt5 unique-ptr qtconcurrent


【解决方案1】:

我终于能够找到工作版本:

class A {
 public:
 void method1();
};
class B {
  std::unique_ptr<A> ptr;
 public:
  void method2() {
    QtConcurrent::run(this->ptr.get(), &A::method1);
  }
}

【讨论】:

    猜你喜欢
    • 2020-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-07
    • 2016-10-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多