Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/140.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.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++ 传递'成员的参考;这';转换为std::thread的参数_C++_Qt - Fatal编程技术网

C++ 传递'成员的参考;这';转换为std::thread的参数

C++ 传递'成员的参考;这';转换为std::thread的参数,c++,qt,C++,Qt,我需要编写一个不属于类MainWindow(这是一个Qt项目)的函数,以便它可以在线程中使用,但我还需要它在线程中使用MainWindow的成员。以下是我编写的代码: void nameChange(TMAPI *tmapi) { tmapi->writeString(0x001bbbc2c, qPrintable(n)); } void MainWindow::on_button_clicked() { std::thread id(nameChange, this-&

我需要编写一个不属于类
MainWindow
(这是一个Qt项目)的函数,以便它可以在线程中使用,但我还需要它在线程中使用
MainWindow
的成员。以下是我编写的代码:

void nameChange(TMAPI *tmapi) {
    tmapi->writeString(0x001bbbc2c, qPrintable(n));
}

void MainWindow::on_button_clicked() {
    std::thread id(nameChange, this->tmapi);
    id.join();
}
我从中得到两个错误(它们是相同的错误,但指向文件
中的不同代码行):


当我传入当前对象(
这个
的)tmapi实例时,如何获得第一种工作方式?谢谢

nameChange
采用
TMAPI*
。您正试图向其传递一个
TMAPI
。因此出现了一个超级神秘的错误:

error: no type named 'type' in 'class std::result_of<void (*(TMAPI))(TMAPI*)>

nameChange
采用
TMAPI*
。您正试图向其传递一个
TMAPI
。因此出现了一个超级神秘的错误:

error: no type named 'type' in 'class std::result_of<void (*(TMAPI))(TMAPI*)>

这是一个TMAPI,没有指针。啊,你抓住我了。我将参数更改为
&this->tmapi
,现在可以工作了。谢谢这是一个TMAPI,没有指针。啊,你抓住我了。我将参数更改为
&this->tmapi
,现在可以工作了。谢谢
error: no type named 'type' in 'class std::result_of<void (*(TMAPI))(TMAPI*)>
std::thread id(nameChange, &this->tmapi);