在非常特定的条件下从静态函数发出信号

时间:2016-10-16 15:30:40

标签: c++ qt c++11 signals libcurl

所以这是我试图开始工作的最小示例代码:

int GekkoFyre::CmnRoutines::curl_xferinfo(void *p, curl_off_t dltotal, curl_off_t dlnow,
                                          curl_off_t ultotal, curl_off_t ulnow)
{
    CurlStatistics stats;
    stats.ul_now = ulnow;
    stats.ul_total = ultotal;
    stats.dl_now = dlnow;
    stats.dl_total = dltotal;
    emit sendXferStats(stats);
}

这是标题:

static int curl_xferinfo(void *p, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal,
                         curl_off_t ulnow);

signals:
    void sendXferStats(const CurlStatistics &stats);

这就是为什么函数需要是静态的:

curl_easy_setopt(curl_ptr, CURLOPT_XFERINFOFUNCTION, curl_xferinfo);
// Pass the struct pointer into the xferinfo function, but note that this is an
// alias to CURLOPT_PROGRESSDATA
curl_easy_setopt(curl_ptr, CURLOPT_XFERINFODATA, &curl_struct.prog);

我从StackOverflow的各个帖子中了解到,在某些条件下可以从静态函数发出信号,例如:Sending signal from static class method in Qt

我想知道的是,在这种情况下我该怎么做?如果可能的话?非常感谢你,因为非常感谢任何帮助。

0 个答案:

没有答案