How to prevent double Glib::signal_timeout execution?

I’m using following construction for progress_fraction animation:

// Animate progress function
Glib::signal_timeout().connect(
    [this]() -> bool
    {
        double current_progress_fraction = get_progress_fraction();

        // Animation in progress
        if (current_progress_fraction < progress_fraction)
        {
            set_progress_fraction(
                current_progress_fraction + PROGRESS_PULSE_STEP
            );

            return true; // continue
        }

        // 100% of value, reset
        set_progress_fraction(
            progress_fraction = 0
        );

        return false; // stop
    },
    PROGRESS_ANIMATION_TIME
);

But when activate new action before current Glib::signal_timeout completed, progress animation going wrong.

How can I stop Glib::signal_timeout before activating new one?

Glib::signal_timeout() returns a sigc::connection. You should store this object. When you activate a new action, you can call sigc::connection::disconnect() on the stored connection before starting the new action’s timeout.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.