Need help in resolving a compiler error: error: invalid conversion from ‘int’ to ‘GIOCondition’
I have a simple cpp 开发者_开发问答file which uses GIO. I have stripped out everything to show my compile error:
Here is the error I get:
My.cpp:16: error: invalid conversion from ‘int’ to ‘GIOCondition’
make[2]: *** [My.o] Error 1
Here is the complete file:
#include <glib.h>
static gboolean
read_socket (GIOChannel *gio, GIOCondition condition, gpointer data)
{
return false;
}
void createGIOChannel() {
GIOChannel* gioChannel = g_io_channel_unix_new(0);
// the following is the line causing the error:
g_io_add_watch(gioChannel, G_IO_IN|G_IO_HUP, read_socket, NULL);
}
I have seen other example using gio, and I am doing the same thing in term of calling G_IO_IN|G_IO_HUP. And the documentation http://www.gtk.org/api/2.6/glib/glib-IO-Channels.html, said I only need to include , which I did.
Can you please tell me how to resolve my error?
One thing I can think of is I am doing this in a cpp file. But g_io_add_watch is a c function?
Thank you for any help. I have spent hours on this but did not get anywhere.
You can Cast it
(GIOCondition) G_IO_IN|G_IO_HUP
or
void createGIOChannel() {
GIOChannel* gioChannel = g_io_channel_unix_new(0);
// the following is the line causing the error:
GIOCondition cond = G_IO_IN|G_IO_HUP;
g_io_add_watch(gioChannel, cond , read_socket, NULL);
}
I guess it is flagging an error as you must be using a CPP Compiler which does strict typechecking.
Incase of a C compiler, that should mostly be a warning.
You can typecast it ((GIOCondition) G_IO_IN|G_IO_HUP) or create a variable of type GIOCondition and pass the same to the function.
精彩评论