Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/161.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ qtconcurrent没有匹配函数用于调用';运行';_C++_Multithreading_Qt - Fatal编程技术网

C++ qtconcurrent没有匹配函数用于调用';运行';

C++ qtconcurrent没有匹配函数用于调用';运行';,c++,multithreading,qt,C++,Multithreading,Qt,要让用户登录,我在下面的类类ProbeConnection中有一个方法:public QObject,QRunnable 要登录的方法称为“按QRunnable类的预期运行” void ProbeConnection::run(QString username, QString password, QString ipAddress, bool fts, bool tts, bool pcap, bool events, bool os_meas) 该方法需要在不同的线程中运行,因为它在没有响

要让用户登录,我在下面的类
类ProbeConnection中有一个方法:public QObject,QRunnable

要登录的方法称为“按QRunnable类的预期运行”

void ProbeConnection::run(QString username, QString password, QString ipAddress, bool fts, bool tts, bool pcap, bool events, bool os_meas)
该方法需要在不同的线程中运行,因为它在没有响应时阻塞gui(该方法用于登录)。 我试图通过运行以下命令使其与
QtConcurrent
一起运行:

QFuture<void> future = QtConcurrent::run(this->run(username, password, ipAddress, fts, tts,  pcap,  events,  os_meas));
QFuture future=QtConcurrent::run(这个->运行(用户名、密码、IP地址、fts、tts、pcap、事件、操作系统));
但我得到的信息是:

调用“run”时没有匹配的函数


当run方法接受参数时,如何启动它?

当使用成员函数调用
qtconcurrent::run
时,您需要正确的
qtconcurrent::run
语法,如中所述

如中所述<当您想要重用QThreadPool中的现有线程时,将使用code>QRunnable,另一方面,
QtConcurrent
通常用于其高级API,并返回QFuture对象以从线程检索结果

要使用
QRunnable::run
,请在子类中重新对其进行采样,并使用
QThreadPool::start()
QRunnable
放入QThreadPool的运行队列中。。。不是通过调用
QtConcurrent::run


在代码中,
ProbeConnection::run
QFuture
都是
void
。。我认为没有理由使用
QtConcurrent
。。或者直接使用它而不使用
QRunnable

为什么不使用此方法?>“我看不出使用QtConcurrent的理由”。在另一个线程中轻松运行函数对我来说似乎是一个很好的理由。@GrecKo,
QRunnable::run
本身被设计为在所述的
QThreadpool
中运行,而不是在
QtConcurrent
中运行;此外,当函数为
void
时有什么意义,
QFuture QtConcurrent::run
会有什么不同?使用更简单
QtConcurrent::run(foo,&foo::function,parameter)
vs必须从
QRunnable
继承,重写
run
函数并在
QThreadPool
@GrecKo中启动它,没错,它可以更简单,但其他静态也很简单。我不知道OP为什么选择
QRunnable::run
,我的答案的实质是如何实现每一个,而不是混合它们。