How to set variable value from gtk_entry? - c

I would like to set var pid from entry, but I got the following warning:
gtk.c:7:6: warning: assignment makes integer from pointer without a cast [enabled by default].
How I can make var pid == entry? It is very imporatant because this program is going to send signal to a process which id (pid) we are going to enter.
#include <gtk/gtk.h>
#include <stdlib.h>
pid_t pid;
void sendSighup(GtkWidget *widget,GtkWidget *entry, gpointer label) {
pid = gtk_entry_get_text(GTK_ENTRY(entry));
kill(pid,SIGHUP);
}
void sendSigint(GtkWidget *widget, gpointer label) {
kill(pid,SIGINT);
}
void sendSigkill(GtkWidget *widget, gpointer label) {
kill(pid,SIGKILL);
}
void sendSigterm(GtkWidget *widget, gpointer label) {
kill(pid,SIGTERM);
}
void sendSigstop(GtkWidget *widget, gpointer label) {
kill(pid,SIGSTOP);
}
accept_clicked (GtkButton *button, GObject *context_object)
{
GtkLabel *accept_lable1 = g_object_get_data (context_object, "label1");
GtkEntry *accept_entry = g_object_get_data (context_object, "entry");
const char *entry_in = gtk_entry_get_text (accept_entry);
gtk_label_set_text (accept_lable1, entry_in);
}
int main( int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *frame;
GtkWidget *table;
GtkWidget *button1;
GtkWidget *button2;
GtkWidget *button3;
GtkWidget *button4;
GtkWidget *button5;
GtkWidget *quit;
GtkWidget *set;
GtkWidget *vseparator;
GtkWidget *entry;
GtkWidget *label;
GtkWidget *label1;
GtkWidget *label2;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Send Signal");
gtk_window_set_default_size(GTK_WINDOW(window), 300, 250);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
frame = gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(window), frame);
button1 = gtk_button_new_with_label("Sighup");
gtk_fixed_put(GTK_FIXED(frame), button1, 8, 15);
gtk_widget_set_size_request(button1, 80, 35);
button2 = gtk_button_new_with_label("Sigint");
gtk_fixed_put(GTK_FIXED(frame), button2, 8, 60);
gtk_widget_set_size_request(button2, 80, 35);
button3 = gtk_button_new_with_label("Sigkill");
gtk_fixed_put(GTK_FIXED(frame), button3, 8, 105);
gtk_widget_set_size_request(button3, 80, 35);
button4 = gtk_button_new_with_label("Sigterm");
gtk_fixed_put(GTK_FIXED(frame), button4, 8, 150);
gtk_widget_set_size_request(button4, 80, 35);
button5 = gtk_button_new_with_label("Sigstop");
gtk_fixed_put(GTK_FIXED(frame), button5, 8, 195);
gtk_widget_set_size_request(button5, 80, 35);
set = gtk_button_new_with_label ("Set");
gtk_fixed_put(GTK_FIXED(frame), set, 200, 80);
gtk_widget_set_size_request(set, 80, 35);
quit = gtk_button_new_with_label("Quit");
gtk_fixed_put(GTK_FIXED(frame), quit, 200, 195);
gtk_widget_set_size_request(quit, 80, 35);
vseparator = gtk_vseparator_new();
gtk_widget_set_size_request(vseparator, 10, 240);
gtk_fixed_put(GTK_FIXED(frame), vseparator, 95, 5);
label = gtk_label_new("Enter PID:");
gtk_fixed_put(GTK_FIXED(frame), label, 165, 20);
label2 = gtk_label_new("PID:");
gtk_fixed_put(GTK_FIXED(frame), label2, 110, 89);
label1 = gtk_label_new("0000");
gtk_fixed_put(GTK_FIXED(frame), label1, 140, 89);
entry = gtk_entry_new();
gtk_fixed_put(GTK_FIXED(frame), entry, 120, 40);
gtk_widget_grab_focus(entry);
g_object_set_data(G_OBJECT(set), "label1", label1);
g_object_set_data(G_OBJECT(set), "entry", entry);
g_signal_connect(GTK_BUTTON (set), "clicked",
G_CALLBACK (accept_clicked), set);
g_signal_connect_swapped(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect(button1, "clicked",
G_CALLBACK(sendSighup), NULL);
g_signal_connect(button2, "clicked",
G_CALLBACK(sendSigint), NULL);
g_signal_connect(button3, "clicked",
G_CALLBACK(sendSigkill), NULL);
g_signal_connect(button4, "clicked",
G_CALLBACK(sendSigterm), NULL);
g_signal_connect(button5, "clicked",
G_CALLBACK(sendSigstop), NULL);
g_signal_connect(G_OBJECT(quit), "clicked",
G_CALLBACK(gtk_main_quit), G_OBJECT(window));
gtk_widget_show_all(window);
gtk_widget_show(entry);
gtk_widget_show(label);
gtk_main();
return 0;
}

In that line you can either use the plain old atoi:
pid = atoi(gtk_entry_get_text(GTK_ENTRY(entry)));
or use a more complex function such as g-ascii-strtod.

gtk_entry_get_text returns char* - a pointer to char. You are assigning a pointer to char to int in your code. This is implementation-defined according to C standard and is not probably what you want, this is why your compiler gives you a warning:
6.3.2.3 p.6:
Any pointer type may be converted to an integer type. Except as
previously specified, the result is implementation-defined. If the
result cannot be represented in the integer type, the behavior is
undefined. The result need not be in the range of values of any
integer type.
For example, take a look at this code which is an exact representation of problem you have:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char *p ="123456";
int i = p;
printf("%d\n", i);
printf("%p\n", p);
exit 0;
}
It prints:
134514096
0x80485b0
Pointer to char is assigned to int in line 7. This yields the same error as in your code:
main.c:7:17: warning: initialization makes integer from pointer
without a cast [enabled by default]
Now let's see what's the result of this assignment - do not forget that this an implementation-defined behavior. First printf prints value of i variable after assignment. Second printf prints an address that a pointer holds using %p specifier which prints a pointer value in an implementation-defined manner. These values turned out to be the same - 0x80485b0 is hexadecimal 134514096. What happened here is pointer value (that is an address) has been assigned to int. The same is happening in your code. C is a very simple language, it doesn't do anything behind your back. It will not automatically convert a series of digits written in a string to an int. To convert string to a number you need to use standard atoi function or a custom function provided by libraries you are using.

Related

how to change multiple widgets property on button click GTK c

I am trying to make UI using GTK in c for raspberry pi 4. I want to change the visibility of different widgets based on button click just to simulate a new page. I have tried everything available on the internet but as I am not that good at coding I cant figure out what is wrong.
can someone please help ?
This program compiles but when I press the button it gives error " assertion failed on gtk_widget_show " and also on widget hide. Also a segmentation fault occurs and the program crashes.
I am using cmake to compile my code. I have attached the error screen shot.
#include <gtk/gtk.h>
typedef struct AppData
{
GtkWidget *label1;
GtkWidget *label2;
} AppData;
static void button1 (gpointer data)
{
AppData *data2 = (AppData*)data;
gtk_widget_hide(data2->label1);
gtk_widget_show(data2->label2);
}
static void button2 ( gpointer data)
{
AppData *data2 = (AppData*)data;
gtk_widget_show(data2->label1);
gtk_widget_hide(data2->label2);
}
int main(int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *fixed;
GtkWidget *btn1;
GtkWidget *btn2;
GtkWidget *box1;
GtkWidget *box2;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "ethercat test 1");
gtk_window_set_default_size(GTK_WINDOW(window), 1000,500);
fixed = gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(window), fixed);
box1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1);
gtk_fixed_put(GTK_FIXED(fixed), box1, 0,0);
box2 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1);
gtk_fixed_put(GTK_FIXED(fixed), box2, 100,100);
AppData *app_data = g_new0 (AppData, 2);
app_data->label1 = gtk_label_new("label1");
gtk_box_pack_start(GTK_BOX(box1),app_data->label1, TRUE,TRUE,0);
app_data->label2 = gtk_label_new("label2");
gtk_box_pack_start(GTK_BOX(box2),app_data->label2, TRUE,TRUE,0);
btn1 = gtk_button_new_with_label("ethercat 1");
gtk_fixed_put(GTK_FIXED(fixed), btn1, 10, 450);
gtk_widget_set_size_request(btn1, 80,30);
btn2 = gtk_button_new_with_label("ethercat 2");
gtk_fixed_put(GTK_FIXED(fixed), btn2, 110, 450);
gtk_widget_set_size_request(btn2, 80,30);
gtk_widget_show_all(window);
g_signal_connect(G_OBJECT(btn1), "clicked", G_CALLBACK(button1), app_data);
g_signal_connect(G_OBJECT(btn2), "clicked", G_CALLBACK(button2), app_data);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_main();
printf("program end\n");
return (0);
}
enter image description here
The function signature of your "clicked" callbacks is wrong. It should be of the form as described in the documentation:
void on_clicked(
GtkButton* self,
gpointer user_data
)
So for example, your button2() function becomes
static void button2 (GtkButton *btn2, gpointer data)
{
AppData *data2 = (AppData*)data;
gtk_widget_show(data2->label1);
gtk_widget_hide(data2->label2);
}

GtkTextView text coloring not working as expected

I'm trying to use GtkTextView for highlighting C++ style comments in code but it does not seem to work right. I want to create a function that first resets all the highlight to default (black) and then paints only the part of the text that matches pattern /.?*/ While the regex part works I have serious problem with Gtk obedience - it just paints the text black and stops. Is there any logical explaination for this? Am I doing something wrong? I'm placing the sample code that should work but it does not. The compilation command is
gcc -o highlight_syntax_comments highlight_syntax_comments.c `pkg-config --cflags --libs gtk+-3.0`
#define GLIB_VERSION_2_28 (G_ENCODE_VERSION (2, 28))
#define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_28
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
GtkTextBuffer *buffer;
GtkTextIter iter;
size_t f_size;
char* string;
int err;
static void highlight_syntax() {
GtkTextIter match_start, match_end;
GtkTextSearchFlags flags;
GtkTextTagTable* table = gtk_text_buffer_get_tag_table (buffer);
GtkTextTag* orange_tag = gtk_text_tag_table_lookup (table, "orange");
GtkTextTag* black_tag = gtk_text_tag_table_lookup (table, "black");
GtkTextTag* green_tag = gtk_text_tag_table_lookup (table, "green");
// reset color to black
gtk_text_buffer_get_start_iter(GTK_TEXT_BUFFER (buffer), &match_start);
gtk_text_buffer_get_end_iter(GTK_TEXT_BUFFER (buffer), &match_end);
gtk_text_buffer_apply_tag (GTK_TEXT_BUFFER (buffer), black_tag, &match_start, &match_end);
// color first 100 chars
gtk_text_buffer_get_iter_at_offset(GTK_TEXT_BUFFER (buffer), &match_start, 0);
gtk_text_buffer_get_iter_at_offset(GTK_TEXT_BUFFER (buffer), &match_end, 100);
gtk_text_buffer_apply_tag (GTK_TEXT_BUFFER (buffer), orange_tag, &match_start, &match_end);
}
static gboolean key_callback(GtkWidget *widget,
GdkEventKey *event,
GtkIMContext *im_context) {
highlight_syntax();
return FALSE;
}
#include <stdio.h>
#include <stdlib.h>
#define FILE_OK 0
#define FILE_NOT_EXIST 1
#define FILE_TO_LARGE 2
#define FILE_READ_ERROR 3
char * c_read_file(const char * f_name, int * err, size_t* f_size) {
char * buffer;
size_t length;
FILE * f = fopen(f_name, "rb");
size_t read_length;
if (f) {
fseek(f, 0, SEEK_END);
length = ftell(f);
fseek(f, 0, SEEK_SET);
buffer = (char *)malloc(length + 1);
read_length = fread(buffer, 1, length, f);
fclose(f);
*err = FILE_OK;
buffer[length] = '\0';
*f_size = length;
}
else {
*err = FILE_NOT_EXIST;
return NULL;
}
return buffer;
}
int main(int argc, gchar *argv[]) {
GtkWidget *window;
GtkWidget *view;
GtkWidget *vbox;
GtkWidget *scrolled_window;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 800, 600);
GtkIMContext *im_context = gtk_im_multicontext_new();
GdkWindow *gdk_window = gtk_widget_get_window(GTK_WIDGET(window));
gtk_im_context_set_client_window(im_context, gdk_window);
gtk_im_context_focus_in(im_context);
vbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
view = gtk_text_view_new();
gtk_widget_add_events(view, GDK_BUTTON_PRESS_MASK);
gtk_box_pack_start(GTK_BOX(vbox), view, TRUE, TRUE, 0);
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_container_add (GTK_CONTAINER (scrolled_window),
vbox);
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));
gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0);
gtk_text_buffer_create_tag(buffer, "orange", "foreground", "#e87d3e", NULL);
gtk_text_buffer_create_tag(buffer, "green", "foreground", "#A6E22E", NULL);
gtk_text_buffer_create_tag(buffer, "black", "foreground", "#000000", NULL);
string = c_read_file("./highlight_syntax_comments.c", &err, &f_size);
gtk_text_buffer_insert(buffer, &iter, string, -1);
highlight_syntax();
gtk_container_add(GTK_CONTAINER(window), scrolled_window);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect(window, "key-press-event",
G_CALLBACK(key_callback), im_context);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
This is explained in the documentation for gtk_text_tag_set_priority() — setting one tag does not remove another, so both the orange and black tags are applying to the text at the same time. Since the black tag was added to the tag table last, its priority is highest, so it overrides the orange tag, even though you applied the orange tag on the text after applying the black tag.
The solution is to give the orange tag a higher priority, or make sure that you remove the black tag from the text that you want to apply the orange tag to.

Redefine a label after a click button in GTK+2

I had the following code and I want to change the value of the label "title" when I press te button "hlpBtn" but I have troubles with it.
#include <gtk/gtk.h>
void button_clicked(GtkWidget *widget, gpointer data)
{
GtkWidget *title = (GtkWidget *) data;
title = gtk_label_new("DECODED!!");
}
int main(int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *table;
GtkWidget *title;
GtkWidget *wins;
GtkWidget *halign;
GtkWidget *halign2;
GtkWidget *hlpBtn;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_widget_set_size_request (window, 650, 850);
gtk_window_set_title(GTK_WINDOW(window), "Windows");
gtk_container_set_border_width(GTK_CONTAINER(window), 15);
table = gtk_table_new(6, 4, FALSE);
gtk_table_set_col_spacings(GTK_TABLE(table), 3);
gtk_table_set_row_spacing(GTK_TABLE(table), 0, 3);
title = gtk_label_new("Decrypting code...");
halign = gtk_alignment_new(0, 0, 0, 0);
gtk_container_add(GTK_CONTAINER(halign), title);
gtk_table_attach(GTK_TABLE(table), halign, 0, 1, 0, 1,
GTK_FILL, GTK_FILL, 0, 0);
halign2 = gtk_alignment_new(0, 1, 0, 0);
hlpBtn = gtk_button_new_with_label("RUN");
gtk_container_add(GTK_CONTAINER(halign2), hlpBtn);
gtk_widget_set_size_request(hlpBtn, 70, 30);
gtk_table_set_row_spacing(GTK_TABLE(table), 3, 5);
gtk_table_attach(GTK_TABLE(table), halign2, 0, 1, 4, 5,
GTK_FILL, GTK_FILL, 0, 0);
g_signal_connect(G_OBJECT(hlpBtn), "clicked",
G_CALLBACK(button_clicked), title);
gtk_container_add(GTK_CONTAINER(window), table);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), G_OBJECT(window));
gtk_widget_show_all(window);
gtk_main();
return 0;
}
My intention is to call the funcition button_clicked when I press hlpBtn and then changue title from "Decrypting code..." to "DECODED!!".
What is wrong here?
Thank you.
Why don't you do something like this, instead of creating a new label?
void button_clicked(GtkWidget *widget, gpointer data)
{
gtk_label_set_text((GtkLabel *)data, "DECODED!!");
}
What's wrong with your code: you take a pointer to an existing label, make a local copy of it, create a new label and overwrite the local pointer with the pointer to the new item. The problem is, overwriting the pointer does by no mean replace the original item within the window. You would need to destroy the existing label and then add the new instance. But as you can see from my code, the solution is much easier than that: just update the existing label with the new content.

error : expected declaration specifiers or ‘...’ before string constant while declaring colorbutton in gtk+

I want to put some color with gtkButton in GTK+ program, but it shows some declaration error as i've specified above. This is the declaration, i've used in the gtk program.
static GdkColor colorRed;//error line 1
gdk_color_parse("red", &colorRed); //error line 2
button1 = gtk_button_new_with_label("button");
gtk_widget_modify_base (button1, GTK_STATE_NORMAL, &colorRed);
but it's displaying error
error: expected declaration specifiers or ‘...’ before string constant //line 1
error: expected declaration specifiers or ‘...’ before ‘&’ token //line 2
gtk_widget_modify_base has been deprecated since 3.0. Use gtk_widget_override_background_color instead. You won't need GdkColor, just GdkRGBA, which is more convenient for cairo anyway.
About your error: I think you're focusing on the wrong part. You snippet is here the compiler sees the error, but lines before are always welcome, and I think your problem is that you're not including the headers for GdkColor.
The declaration to color the button was correct but i had declared it as global i.e outside the main() function to use the color in multiple function. So, when i put the declaration in side the main() function and replace gtk_widget_modify_base() to gtk_widget_modify_bg() then it's working perfectly.
Here is corrected code
#include <gtk/gtk.h>
static void destroy (GtkWidget *window, gpointer data);
GtkWidget *window;
GtkWidget *table;
GtkWidget *button;
GtkWidget *button1[20][20];
GtkWidget *button2;
GtkWidget *button3;
GtkWidget *title;
GtkWidget *label;
static char *values[100] =
{ "127.0.0.1", "Idle",
"192.168.73.129", "Idle",
"192.168.73.130", "Idle",
"192.168.73.131", "Idle",
"192.168.73.132", "Idle",
"192.168.73.133", "Idle",
"192.168.73.134", "Idle",
};
int main(int argc, char *argv[])
{ gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL); //gtk_scrolled_window_new(NULL, NULL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 550, 700);
gtk_window_set_title(GTK_WINDOW(window), "Client Activity Monitor");
gtk_container_set_border_width(GTK_CONTAINER(window), 25);
g_signal_connect (G_OBJECT (window), "destroy",G_CALLBACK (destroy), NULL);
table = gtk_table_new(4, 2, TRUE);
gtk_table_set_row_spacings(GTK_TABLE(table), 2);
gtk_table_set_col_spacings(GTK_TABLE(table), 2);
GdkColor colorRed;//color declaration
gdk_color_parse("red", &colorRed);//color assignment
int i = 0;
int j = 0;
int pos = 0;
title = gtk_frame_new("Client Logs");
label = gtk_label_new("server: waiting for connections...\n");
gtk_frame_set_shadow_type(GTK_FRAME(title), GTK_SHADOW_IN);
gtk_table_attach_defaults(GTK_TABLE(table), title, 0, 1, 0, 1);
button3 = gtk_button_new_with_label("Start Server");
gtk_widget_modify_fg(button3, GTK_STATE_NORMAL, &colorRed);//color use
gtk_table_attach_defaults(GTK_TABLE(table), button3, 1, 2, 0, 1);
gtk_container_add (GTK_CONTAINER (title), label);
gtk_widget_show_all(title);
for(i=0; i < 6; i++) {
for( j=0; j < 2; j++) {
button1[i][j] = gtk_button_new_with_label(values[pos]);
gtk_widget_modify_fg(button1[i][j], GTK_STATE_NORMAL, &colorRed);
gtk_table_attach_defaults(GTK_TABLE(table), button1[i][j], j, j+1, i+1, i+1+1 );
pos++;
}
}
gtk_container_add(GTK_CONTAINER(window), table);
g_signal_connect_swapped (G_OBJECT (button3), "clicked",G_CALLBACK (destroy),(gpointer) window);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
static void destroy (GtkWidget *window, gpointer data)
{
gtk_main_quit ();
}

Gtk+ Callback functions and signals help

I have the following example from here, it shows this under the "Increase - Decrease" title.
#include <gtk/gtk.h>
gint count = 0;
char buf[5];
void increase(GtkWidget *widget, gpointer label)
{
count++;
sprintf(buf, "%d", count);
gtk_label_set_text(label, buf);
}
void decrease(GtkWidget *widget, gpointer label)
{
count--;
sprintf(buf, "%d", count);
gtk_label_set_text(label, buf);
}
int main(int argc, char** argv) {
GtkWidget *label;
GtkWidget *window;
GtkWidget *frame;
GtkWidget *plus;
GtkWidget *minus;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 250, 180);
gtk_window_set_title(GTK_WINDOW(window), "+-");
frame = gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(window), frame);
plus = gtk_button_new_with_label("+");
gtk_widget_set_size_request(plus, 80, 35);
gtk_fixed_put(GTK_FIXED(frame), plus, 50, 20);
minus = gtk_button_new_with_label("-");
gtk_widget_set_size_request(minus, 80, 35);
gtk_fixed_put(GTK_FIXED(frame), minus, 50, 80);
label = gtk_label_new("0");
gtk_fixed_put(GTK_FIXED(frame), label, 190, 58);
gtk_widget_show_all(window);
g_signal_connect(window, "destroy",
G_CALLBACK (gtk_main_quit), NULL);
g_signal_connect(plus, "clicked",
G_CALLBACK(increase), label);
g_signal_connect(minus, "clicked",
G_CALLBACK(decrease), label);
gtk_main();
return 0;
}
what I'm wondering is, the g_signal_connect(plus, "clicked",G_CALLBACK(increase), label); function sends the "label" to the function increase, where its arguments are void increase(GtkWidget *widget, gpointer label). Now in the increase function the gtk_label_set_text() function requires a data type of GtkLabel as its first argument but I only see a GtkWidget variable and a void pointer label as the arguments to the increase function. If that is so how does the gtk_label_set_text() work?.
In C (but not C++), you can implicitly cast a void* to a pointer to any other type. It's very commonly seen when allocating memory with malloc, which returns a void*:
int *myIntArray = malloc(10 * sizeof(int)); // allocate array of 10 ints
Your code is doing the same thing, just with parameter passing:
void gtk_label_set_text(GtkLabel *label, const char *text);
void *label = ...;
gtk_label_set_text(label, "some string"); // label is implicitly cast from
// void* to GtkLabel*

Resources