(C ++)Gtk-WARNING **:找不到信号处理程序'。你用-rdynamic编译了吗?

时间:2016-05-18 16:35:11

标签: c++ linux gtk glade

我是使用GTK +进行C ++ GUI编程的新手,我在使用其中一个按钮的信号处理程序时遇到问题,在编译和运行时,我收到以下警告。有谁知道我做错了什么或丢失了什么?

(Project Thoth:4359):Gtk-WARNING **:无法找到信号处理程序' on_login_clicked'。你用-rdynamic编译了吗?

这是我的cpp文件

dups <- data.table (id = c('11', '11', '11', '22','22',
  '88', '99','44','44', '55'),
  date = mdy(c("1-01-2016", "1-02-2016", "1-02-2016","2-01-2016", 
  "2-02-2016")))

so.sample <- dups[, rank := frank(dups, date, ties.method = "average"), by = id]

和我的林间空地文件

#include <cstdlib>
#include <cstdio>
#include <string>
#include <gtk/gtk.h>
#include <iostream>
extern "C"
using namespace std;

int main(int argc, char *argv[])
{
GtkEntry *e1;//textbox1
GtkEntry *e2;//textbox2
GtkEntry *e3;//textbox3

GtkBuilder *gtkBuilder;
GtkWidget *window;

gtk_init(&argc, &argv);

gtkBuilder = gtk_builder_new();
gtk_builder_add_from_file(gtkBuilder, "Unsaved 1.glade", NULL);
window = GTK_WIDGET(gtk_builder_get_object(gtkBuilder, "Login"));

gtk_builder_connect_signals(gtkBuilder, window);

g_object_unref(G_OBJECT(gtkBuilder));
gtk_widget_show(window);
gtk_main();
cout << "Login window loaded";
return 0;
}

G_MODULE_EXPORT void  on_login_clicked()
{
printf("Request Detected\n");
GtkBuilder  *gtkBuilder;
GtkWidget *window;

gtkBuilder = gtk_builder_new();
gtk_builder_add_from_file(gtkBuilder, "Unsaved 1.glade", NULL);

GtkEntry *e1;
GtkEntry *e2;
e1 = GTK_ENTRY( gtk_builder_get_object( gtkBuilder, "user1" ));
e2 = GTK_ENTRY( gtk_builder_get_object( gtkBuilder, "pass"));
gtk_builder_connect_signals(gtkBuilder, e1);
const char *home;
home = gtk_entry_get_text(e1);
cout << home;
}

也用于编译我使用了以下标志

    <?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<interface>
  <requires lib="gtk+" version="3.0"/>
  <object class="GtkApplicationWindow" id="Login">
    <property name="can_focus">False</property>
    <property name="window_position">center</property>
    <property name="default_width">400</property>
    <property name="default_height">300</property>
    <signal name="destroy" handler="on_window_destroy" swapped="no"/>
    <child>
      <object class="GtkLayout" id="layout1">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <child>
          <object class="GtkLabel" id="Label">
            <property name="width_request">100</property>
            <property name="height_request">80</property>
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="label" translatable="yes">Project Thoth
</property>
            <property name="angle">0.089999999999999997</property>
            <attributes>
              <attribute name="weight" value="bold"/>
            </attributes>
          </object>
          <packing>
            <property name="x">156</property>
            <property name="y">14</property>
          </packing>
        </child>
        <child>
          <object class="GtkEntry" id="user1">
            <property name="width_request">166</property>
            <property name="height_request">80</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
          </object>
          <packing>
            <property name="x">128</property>
            <property name="y">72</property>
          </packing>
        </child>
        <child>
          <object class="GtkLabel" id="label1">
            <property name="width_request">100</property>
            <property name="height_request">80</property>
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="label" translatable="yes">Username: 
</property>
          </object>
          <packing>
            <property name="x">121</property>
            <property name="y">52</property>
          </packing>
        </child>
        <child>
          <object class="GtkEntry" id="pass">
            <property name="width_request">166</property>
            <property name="height_request">84</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
          </object>
          <packing>
            <property name="x">129</property>
            <property name="y">130</property>
          </packing>
        </child>
        <child>
          <object class="GtkLabel" id="label3">
            <property name="width_request">100</property>
            <property name="height_request">80</property>
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="label" translatable="yes">Password:

</property>
          </object>
          <packing>
            <property name="x">117</property>
            <property name="y">123</property>
          </packing>
        </child>
        <child>
          <object class="GtkButton" id="button1">
            <property name="label" translatable="yes">Login</property>
            <property name="width_request">70</property>
            <property name="height_request">29</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="receives_default">True</property>
            <property name="relief">half</property>
            <signal name="clicked" handler="on_login_clicked" swapped="no"/>
          </object>
          <packing>
            <property name="x">171</property>
            <property name="y">191</property>
          </packing>
        </child>
        <child>
          <object class="GtkLabel" id="label2">
            <property name="width_request">105</property>
            <property name="height_request">35</property>
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="label" translatable="yes">save info login ?</property>
          </object>
          <packing>
            <property name="x">154</property>
            <property name="y">227</property>
          </packing>
        </child>
        <child>
          <object class="GtkSwitch" id="switch1">
            <property name="width_request">74</property>
            <property name="height_request">23</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
          </object>
          <packing>
            <property name="x">166</property>
            <property name="y">263</property>
          </packing>
        </child>
      </object>
    </child>
  </object>
</interface>

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

这条消息给出了一个很好的建议:用-rdynamic编译(实际链接),所以用以下代码编译你的代码:

 g++ -rdynamic  -o Project_Thoth -Wall -g main.cpp \
     $(pkg-config --cflags --libs gtk+-3.0 gmodule-2.0 )

顺便说一下,我强烈建议避免在可执行文件名中留一个空格。所以Project_Thoth不是"Project Thoth"。另外,不要忘记要求警告(至少-Wall,也许添加 -Wextra)和调试信息(-g),这是非常的非常有用,特别是使用gdb调试器来调试程序(或使用valgrind来查找内存泄漏)。

调试程序后,出于基准测试目的,您可能会要求编译器进行优化(因此添加-O2)。

顺便说一句,如果你真的想将GTK与C ++(不仅仅是C)一起使用,请考虑gtkmm。但是你可以用普通的C99编写你的GTK程序(所以没有cout,而是printf)。如果C ++对你很重要,甚至可以考虑转换到Qt(另一个小部件工具包,在C ++中)。

如果使用GTK(不是gtkmm)在C ++中编码,最好将extern "C" 全部声明为与GTK相关的代码。