Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7548403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:41:24+00:00 2026-05-30T09:41:24+00:00

I am trying to code a static callback function that is called frequently from

  • 0

I am trying to code a static callback function that is called frequently from another static function within the same class. My callback function needs to emit a signal but for some reason it simply fails to do so. I have put it under a debugger and the slot never gets called. However when I place the code I used to emit the data in a non-static function it works. Is there a reason I cannot emit a signal from a static function? I have tried declaring a new instance of the class and calling the emit function but with no luck.

class Foo
{
signals:
    emitFunction(int);
private:
    static int callback(int val)
    {
        /* Called multiple times (100+) */
        Foo *foo = new Foo;
        foo.emitFunction(val);
    }
    void run()
    {
        callback(percentdownloaded);
    }
};

I have posted some basic code that demonstrates what I am attempting to do. I will post full code upon request.

Edit: I am posting the full code since this is kind of an odd scenario. http://pastebin.com/6J2D2hnM

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:41:25+00:00Added an answer on May 30, 2026 at 9:41 am

    That is not going to work, because you are creating a new Foo every time you enter that static function, and you do not connect a signal to a slot.

    So, the fix would be to pass the object to that function :

    class Foo
    {
    signals:
        emitFunction(int);
    private:
        static int callback(int val, Foo &foo)
        {
            /* Called multiple times (100+) */
            foo.emitFunction(val);
        }
        void run()
        {
            callback(percentdownloaded, *this);
        }
    };
    

    Another option is to use postEvent, but I wouldn’t recommend it.


    Since you can not modify callback’s signature, you can do it like this :

    class Foo
    {
    signals:
        emitFunction(int);
    private:
        static int callback(int val)
        {
            /* Called multiple times (100+) */
            theFoo->emitFunction(val);
        }
        static Foo *theFoo;
        void run()
        {
            callback(percentdownloaded, *this);
        }
    };
    

    but you’ll have to initialize that static variable somewhere.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have repetitive code that i am trying to refactor into a generic function
I am trying to encrypt some data with the following code: public static byte[]
I am trying to learn how to call this write_data(…) function from the funmain()
Hi I am trying to pass a callback which is a member function. I
When trying to compile with Code::Blocks the example that comes up with GTK+: #include
I am trying to send the events from one Java class to Activity. Scenario
I'm trying to PInvoke into this C++ library function: int Initialize(Callback* callback); struct Callback
There is a C library (which I cannot change) that supports a callback function
Current code: public static void WhoIsOnline(string worldName, WhoIsOnlineReceived callback) { string url = http://www.tibia.com/community/?subtopic=worlds&world=
I have the following code, in which Boost.Local uses a function callback to load

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.