Reputation:
Please look in the below code.
guint id = g_timeout_add (5000,(GSourceFunc)fun(), NULL);
bool fun()
{
return false;
}
problem 1. The id vale I am getting is always 0. problem 2. As per the man page [https://developer.gnome.org/glib/stable/glib-The-Main-Event-Loop.html#g-timeout-add] for the first time, fun() should get call after 5 sec but it is getting called as usual.
Could any one please help me to get the correct id vale and to call the fun() after 5 sec.
I checked the log and below error is showing.
(process:369): GLib-CRITICAL **: g_timeout_add_full: assertion 'function != NULL' failed
I gone through the online documents but didn't get appropriate answer.
Upvotes: 0
Views: 736
Reputation: 5463
To pass a function pointer to g_timeout_add(), you should not call the function you want to pass:
guint id = g_timeout_add (5000,(GSourceFunc)fun(), NULL);
As fun()
return false
, once casted to (GSourceFunc)
it's equivalent to NULL
.
The correct invocation would be:
guint id = g_timeout_add (5000,(GSourceFunc)fun, NULL);
Upvotes: 2