我有一个字符串,其中包含一个整数值(的数字),我想获得这个值作为一个int.我知道还有其他方法可以做到这一点,如atoi():但是,我真的很想用glib来做这件事.这样的解析/转换功能是否存在?
现在有没有人可以找到一些关于 gtk/glib 网络的好的教程/代码示例。我正在尝试编写一个客户端应用程序,该应用程序连接到一个简单的服务器,该服务器使用 Gtk2 回显它接收到的内容,但我不知道如何去做。我想在不使用线程的情况下进行异步读/写,但我不确定什么是最好的方法。API 参考没有太大帮助 - GIOChannel、GIOStream、GSocketClient 等 - 使用哪一个?
回退是在另一个线程中使用阻塞 IO。
我对便携性不感兴趣。
“咆哮:GTk / GLib 开发人员如何期望人们在没有良好文档的情况下使用他们的框架?当我可以使用 QT 来做时,我为什么还要费心。我不想学习更多的 C,这就是我费心的原因!”
Glib 2.30 API允许通过GThreadPriority枚举设置线程优先级。然而,该 API从 2.32 开始已被弃用,我找不到任何有关使用新 API 设置线程优先级的信息。我按 Ctrl+F 浏览了API 参考中所有与线程相关的部分,但没有发现任何与优先级相关的内容。谷歌似乎也不知道任何事情。
那么在 2.32 API 中是否可以为线程分配优先级呢?如果是,如何在创建时执行此操作?是否可以在创建线程后更改它?我知道 pthread 支持所有这些,但我更愿意坚持使用独立于平台的 Glib API。
我正在尝试在CentOS5上构建glib-2.36.4.我意识到升级到6会更明智,但由于客户的要求,这是不可能的.
我已经开始构建make了,我得到了以下错误.错误抱怨系统上不存在automake-1.13.但是,我构建了automake 1.14并安装了它.automake --version输出正确的版本.
我已经安装了一个yum列表 grep automake确保automake没有冲突的安装.
我试过谷歌搜索问题,但我无法想出任何东西.
make[4]: Entering directory `/home/tharper/glib-2.36.4/docs/reference/glib'
cd ../../.. && /bin/sh /home/tharper/glib-2.36.4/missing
automake-1.13 --gnu docs/reference/glib/Makefile
/home/tharper/glib-2.36.4/missing: line 81: automake-1.13: command not found
WARNING: 'automake-1.13' is missing on your system.
You should only need it if you modified 'Makefile.am' or
'configure.ac' or m4 files included by 'configure.ac'.
The 'automake' program is part of the GNU Automake package:
<http://www.gnu.org/software/automake>
It also requires GNU Autoconf, GNU m4 and Perl in order to run:
<http://www.gnu.org/software/autoconf>
<http://www.gnu.org/software/m4/>
<http://www.perl.org/>
make[4]: *** …Run Code Online (Sandbox Code Playgroud) 我正在关注http://www.micahcarrick.com/gsettings-python-gnome-3.html以使用来自 python 的 GSettings,并且我已经成功读取了一个值:
from gi.repository import Gio
gso=Gio.Settings.new("org.gnome.desktop.wm.preferences")
gso.get_value("focus-mode")
Run Code Online (Sandbox Code Playgroud)
这将返回一个“GLib.Variant”,它是一组枚举值中的一个。为了获得我可以设置的有效枚举,我使用:
gso.get_range("focus-mode")
Run Code Online (Sandbox Code Playgroud)
但是,文档说
g_settings_get_range 自 2.40 版起已弃用,不应在新编写的代码中使用。使用 g_settings_schema_key_get_range() 代替。
那么,我如何使用 python 中的 g_settings_schema_key_get_range?
更一般地说,我怎样才能内省 Gio 以找出如何在给定 C 文档的情况下从 python 中使用它?
我想为我的 vala 类创建一个线程安全的单例实例。
如您所知,如果未正确实现,单例可能会导致线程问题。
尝试在 python 3 中使用 导入 glib 时from gi.repository import glib,我收到一条错误消息:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 2135, in _find_spec
AttributeError: 'DynamicImporter' object has no attribute 'find_spec'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/gi/importer.py", line 53, in find_module
'introspection typelib not found' % namespace)
ImportError: cannot import name glib, introspection typelib not found
Run Code Online (Sandbox Code Playgroud)
我在 Ubuntu 14.04 上使用 apt-get 安装了所有 python glib/dev …
我在堆栈溢出上搜索以找到与我的问题相关的答案。但我没有找到任何答案。
我有一个启动线程的主线程(我的 main() 函数)。新线程运行 GMainLoop。g_io_watch在我的主函数中,我不断通过调用一些文件描述符来添加源。但如果事件被调度,我会得到垃圾数据。
下面是我正在尝试的代码的一小部分:
GMainLoop *loop;
gpointer event_loop_thread(gpointer arg)
{
g_main_loop_run(loop);
g_main_loop_unref(loop);
return NULL;
}
int init()
{
loop = g_main_loop_new(NULL, FALSE);
g_thread_new(NULL, event_loop_thread, NULL);
return 0;
}
gboolean __hci_service(GIOChannel *source, GIOCondition condition, gpointer data)
{
// Doing something
return FALSE;
}
int main()
{
init();
int _adapter_id = hci_devid("hci0");
int hci_dev = hci_open_dev(_adapter_id);
GIOChannel *p_hci_io = g_io_channel_unix_new(dev_id);
GIOCondition cond = (GIOCondition)(G_IO_IN);
g_io_add_watch(p_hci_io, cond, __hci_service, NULL);
while (true);
// I will close file descriptor
return 0; …Run Code Online (Sandbox Code Playgroud) 我正在尝试GLib.ThreadPool在Vala中使用s,但在搜索Google Code和现有文档后,我找不到任何好用的例子.我自己尝试使用它们导致未处理的GLib.ThreadErrors.
例如,考虑以下26行,它们是整数范围的乘法.
class Range {
public int low;
public int high;
public Range(int low, int high) {
this.low = low;
this.high = high;
}
}
void multiply_range(Range r) {
int product = 1;
for (int i=r.low; i<=r.high; i++)
product = product * i;
print("range(%s, %s) = %s\n",
r.low.to_string(), r.high.to_string(), product.to_string());
}
void main() {
ThreadPool<Range> threads;
threads = new ThreadPool<Range>((Func<Range>)multiply_range, 4, true);
for (int i=1; i<=10; i++)
threads.push(new Range(i, i+5));
}
Run Code Online (Sandbox Code Playgroud)
编译它们的 …
假设我有这样的方法
<interface name="org.Test.ChildTest">
<!-- set_age(guint32 new_age): sets new age -->
<method name="set_age">
<arg type="u" name="new_age" direction="in"/>
</method>
Run Code Online (Sandbox Code Playgroud)
在我的方法表中,我有:
{ (GCallback) child_test_set_age, dbus_glib_marshal_child_test_BOOLEAN__UINT_POINTER, 0 }
Run Code Online (Sandbox Code Playgroud)
和正确的GObject方法签名是:
gboolean
child_test_set_age (ChildTest *childTest, guint ageIn, GError** error)
Run Code Online (Sandbox Code Playgroud)
为什么child_test_set_age()即使回调参数与我的XML中指定的回调参数不匹配,我的方法仍会在DBus上调用?例如,如果我之后添加另一种说法guint ageIn,像一个char*或guint或其他一些随机类型?
我注意到如果DBus函数包含方向为OUT的成员,这将不起作用.似乎任何类型IN的不必要的参数都会被丢弃,并且调用会像往常一样完成.
虽然我认为这没有任何区别,但我使用的是D-BUS绑定工具0.94,glib-2.30.0和dbus-glib 0.94.