简体   繁体   English

std :: thread :: thread( <unresolved overloaded function type> )在Qt中

[英]std::thread::thread(<unresolved overloaded function type>) in Qt

The other answers I read on this website didn't seem relevant to my issue. 我在该网站上阅读的其他答案似乎与我的问题无关。 Anyway, in my mainwindow.cpp file I have a function that needs access to the ui namespace: 无论如何,在我的mainwindow.cpp文件中,我有一个需要访问ui名称空间的函数:

 do
    {
        intrecv= recv(s1, buffer, 10000,0);
        if(intrecv > 0)
        {
            recvData = buffer;
            ui->textEdit->setText("Connection occurred.\n");
        }   
    }while(intrecv > 0);

Here are my preprocessor commands: 这是我的预处理器命令:

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <thread>
#include <string>
#include <QString>

In my mainwindow.h file I prototyped the receive function as such: 在我的mainwindow.h文件中,接收函数原型如下:

    class MainWindow : public QMainWindow
{
    Q_OBJECT
    void receiveFunction();

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:
    void on_pushButton_clicked();

    void on_lineEdit_returnPressed();

private:
    Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H

Then, in mainwindow.cpp, I called that receive function in a thread in another function: 然后,在mainwindow.cpp中,我在另一个函数的线程中调用了该接收函数:

    void MainWindow::on_pushButton_clicked()
{
    connectFunction();
    std::thread t1(receiveFunction);
    t1.detach();
}

An example you could try to replicate my problem is make a pushbutton and a textEdit field. 您可以尝试复制我的问题的一个示例是创建一个按钮和一个textEdit字段。 Have the pushbutton's slot call a function that edits the textEdit field. 让按钮的插槽调用一个用于编辑textEdit字段的函数。

edit: I forgot to mention: for my mini example, don't just have it edit the textEdit field, have it receive data and edit the textEdit field. 编辑:我忘了提一下:在我的迷你示例中,不仅仅是让它编辑textEdit字段,让它接收数据并编辑textEdit字段。

The error message seems to hint that there are multiple overloads of the reveiveFunction function, but that might be misleading (if the code above is correct). 错误消息似乎暗示reveiveFunction函数有多个重载,但这可能会引起误解(如果上面的代码正确)。 There are two things inherently wrong in the line: 该行有两个固有的错误:

std::thread t1(receiveFunction);

First is that you cannot take the address of a member function without providing the type qualification (and a member function does not decay to a pointer to member function). 首先,如果不提供类型限定条件,就不能获取成员函数的地址(并且成员函数不会衰减到指向成员函数的指针)。 The second problem is that a non-static member function requires an object on which it will be called, which you are not providing. 第二个问题是,非静态成员函数需要一个您将不提供的对象,该对象将在该对象上被调用。 That statement can be fixed by doing: 该语句可以通过执行以下操作来修复:

std::thread t1(&MainWindow::receiveFunction, this);

That will correctly take the address of the member function, and provide the this pointer on which the function will be evaluated. 这将正确地获取成员函数的地址,并提供将在其上评估函数的this指针。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 的std ::线程 <unresolved overloaded function type> 错误 - std::thread <unresolved overloaded function type> error C++ 多线程错误:没有匹配的 function 调用 'std::thread::thread(<unresolved overloaded function type></unresolved> - C++ Multithreading Error : no matching function for call to 'std::thread::thread(<unresolved overloaded function type> 提升线程错误<unresolved overloaded function type> - boost thread error <unresolved overloaded function type> 将模板(没有规范)传递给 std::thread() 会产生错误:<unresolved overloaded function type> 匹配错误</unresolved> - passing template (without a specification) to an std::thread() gives error : <unresolved overloaded function type> matching Error 我的类中的c ++ condition_variable wait_for谓词,std :: thread <unresolved overloaded function type> 错误 - c++ condition_variable wait_for predicate in my class, std::thread <unresolved overloaded function type> error &#39;std :: thread :: thread&#39;:没有重载函数需要7个参数 - 'std::thread::thread': no overloaded function takes 7 arguments boost :: thread :: thread( <unresolved overloaded function type> ,int)-模板化的类成员函数 - boost::thread::thread(<unresolved overloaded function type>, int) - templated class member function boost :: thread_group :: create_thread( <unresolved overloaded function type> 错误 - boost::thread_group::create_thread(<unresolved overloaded function type> error std::transfrom 中未解决的重载 function 类型 - Unresolved overloaded function type in std::transfrom 从 boost::thread 调用模板化 function 时“未解决的重载 function 类型” - “unresolved overloaded function type” when calling templated function from boost::thread
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM