[英]How do I make GTK+ 3.0 signal handler work on Windows 10 using MSYS2 and Mingw-W64?
This is the code for my application part1.c
:这是我的应用程序part1.c
的代码:
#include <stdlib.h>
#include <sys/types.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>
#include <gtk/gtkx.h>
#include <gtk/gtk.h>
#include <math.h>
#include <ctype.h>
GtkWidget *window;
GtkWidget *fixed1;
GtkWidget *button1;
GtkWidget *label1;
GtkBuilder *builder;
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
builder = gtk_builder_new_from_file("part1.glade");
window = GTK_WIDGET(gtk_builder_get_object(builder, "window"));
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_builder_connect_signals(builder, NULL);
fixed1 = GTK_WIDGET(gtk_builder_get_object(builder, "fixed1"));
button1 = GTK_WIDGET(gtk_builder_get_object(builder, "button1"));
label1 = GTK_WIDGET(gtk_builder_get_object(builder, "label1"));
gtk_widget_show(window);
gtk_main();
return EXIT_SUCCESS;
}
void on_button1_clicked(GtkButton *b)
{
gtk_label_set_text(GTK_LABEL(label1), (const gchar*)"Hello World!");
}
This is the part1.glade
file:这是part1.glade
文件:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.0"/>
<object class="GtkWindow" id="window">
<property name="can_focus">False</property>
<property name="resizable">False</property>
<property name="default_width">640</property>
<property name="default_height">480</property>
<child>
<placeholder/>
</child>
<child>
<object class="GtkFixed" id="fixed1">
<property name="width_request">640</property>
<property name="height_request">480</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label1">
<property name="width_request">190</property>
<property name="height_request">20</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">label</property>
</object>
<packing>
<property name="x">7</property>
<property name="y">8</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">button</property>
<property name="width_request">100</property>
<property name="height_request">20</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="on_button1_clicked" swapped="no"/>
</object>
<packing>
<property name="x">136</property>
<property name="y">6</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
To compile the program on Windows 10 I use MSYS2 and Mingw-W64: I type gcc `pkg-config --cflags gtk+-3.0` part1.c -o part1.exe `pkg-config --libs gtk+-3.0` -lm
The option -rdynamic
is not available on Windows and the problem I'm having is that when I click the button, nothing happens.为了在 Windows 10 上编译程序,我使用 MSYS2 和 Mingw-W64:我输入gcc `pkg-config --cflags gtk+-3.0` part1.c -o part1.exe `pkg-config --libs gtk+-3.0` -lm
选项-rdynamic
在 Windows 上不可用,我遇到的问题是当我单击按钮时,没有任何反应。 The following error is displayed on MSYS2: MSYS2 上显示以下错误:
(part1.exe:608): Gtk-WARNING **: 11:26:19.469: Could not find signal handler 'on_button1_clicked'. Did you compile with -rdynamic?
What should I do for the on_button1_clicked
signal handler to work on Windows 10?我应该怎么做on_button1_clicked
信号处理程序才能在 Windows 10 上工作? The same code runs without a flaw on Linux when compiled with -rdynamic
but this option is not available on Windows.使用-rdynamic
编译时,相同的代码在 Linux 上运行没有缺陷,但此选项在 Windows 上不可用。 What should I do here?我应该在这里做什么?
The trick here is to declare the function void on_button1_clicked(GtkButton *b)
as G_MODULE_EXPORT void on_button1_clicked(GtkButton *b)
This should do the trick!这里的技巧是将函数void on_button1_clicked(GtkButton *b)
为G_MODULE_EXPORT void on_button1_clicked(GtkButton *b)
这应该可以解决问题!
CREDIT: http://blog.latepaul.com/glade-gtk-on-windows-with-msys2信用: http : //blog.latepaul.com/glade-gtk-on-windows-with-msys2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.