需要帮助解决编译器错误:错误:从“int”转换无效;到“GIO条件”
我有一个使用 GIO 的简单 cpp 文件。我已经删除了所有内容以显示我的编译错误:
这是我得到的错误:
My.cpp:16: error: invalid conversion from ‘int’ to ‘GIOCondition’
make[2]: *** [My.o] Error 1
这是完整的文件:
#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);
}
我已经看到使用 gio 的其他示例,并且我在调用 G_IO_IN|G_IO_HUP 方面做了同样的事情。 以及文档 http://www.gtk.org/api /2.6/glib/glib-IO-Channels.html 说我只需要包含 ,我做到了。
您能告诉我如何解决我的错误吗?
我能想到的一件事是我在 cpp 文件中执行此操作。但是g_io_add_watch是ac函数吗?
感谢您的帮助。我花了几个小时在这上面,但没有取得任何进展。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以投射它
或
You can Cast it
or
我猜它正在标记一个错误,因为您必须使用执行严格类型检查的 CPP 编译器。
对于 C 编译器,这主要应该是一个警告。
您可以对其进行类型转换 ((GIOCondition) G_IO_IN|G_IO_HUP) 或创建 GIOCondition 类型的变量并将其传递给函数。
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.