0

So this is the minimal example code I'm attempting to get to work:

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);
}

And this is the header:

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);

And this is the reason why the function needs to be static:

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);

I know from various posts throughout StackOverflow that it is possible under certain conditions to emit a signal from a static function, such as this one: Sending signal from static class method in Qt

What I want to know is, how do I do that in this instance? If it is at all possible? Thank you so much in advance, as any help is immensely appreciated.

Community
  • 1
  • 1
Phobos D'thorga
  • 439
  • 5
  • 17
  • The answer you linked basically says you need to pass an object to the static function somehow. Either as a parameter or as a global/static variable. – krzaq Oct 16 '16 at 15:33
  • I'm actually not sure how to do it as a global variable, @krzaq. Would you mind posting an example? – Phobos D'thorga Oct 16 '16 at 15:36
  • 1
    Check out the second example in that post. `Foo::theFoo` is a static `Foo*` that is used to emit the signal. – krzaq Oct 16 '16 at 15:37
  • @krzaq, thank you, but I'm not sure how and where to initialise the example `static Foo *theFoo;`. I'm getting errors when I apply it to my situation, so I must be doing it wrong. – Phobos D'thorga Oct 16 '16 at 15:39
  • 1
    You need to initialize it before using it, I'd do it about the same time as initializing curl – krzaq Oct 16 '16 at 15:40
  • But /how/ do I initialise it? I know it's something simple but for some reason, I'm not getting it. I really do apologise... – Phobos D'thorga Oct 16 '16 at 15:41
  • 1
    Assign a pointer to a `Foo` instance. Either have a `Foo` object with static/automatic lifetime and just say `Foo::theFoo = &fooObj` or just allocate it with `new` - but in this case I'd use `unique_ptr` and `make_unique` instead – krzaq Oct 16 '16 at 15:43
  • Thank you so much, @krzaq, it's greatly appreciated :) And yes, a smart pointer would be a good idea. – Phobos D'thorga Oct 16 '16 at 15:46

0 Answers0