MSYS2 в Windows 10 с Glade (сбой gtk_entry_get_text: утверждение 'GTK_IS_ENTRY (entry)') - PullRequest
0 голосов
/ 02 ноября 2019

К сожалению, я новичок в программировании на C, и у меня много проблем с совместимостью внешних библиотек между Linux и Windows.

Я пытаюсь научиться использовать GTK 3, использовать Glade для созданияинтерфейс и geany, чтобы написать код в GCC

Я ищу решение в Интернете в течение 4 дней, но я не понимаю, как его решить: ниже приведена ошибка, которая появляется, когда "Нажата кнопка «ОК».

Пожалуйста, наберитесь терпения, я не знаю, кого сейчас спросить. Спасибо за вашу помощь.

(test:1644): Gtk-CRITICAL **: 11:47:31.588: gtk_entry_get_text: assertion 'GTK_IS_ENTRY (entry)' failed

Код, написанный в GCC через Geany

#include <stdio.h>
#include <gtk/gtk.h>
#include <gmodule.h>

int main(int argc, char *argv[])
{
    GtkBuilder      *builder; 
    GtkWidget       *window;


    gtk_init(&argc, &argv);

    builder = gtk_builder_new();
    gtk_builder_add_from_file (builder, "test.glade", NULL);

    window = GTK_WIDGET(gtk_builder_get_object(builder, "TestWin"));



    gtk_builder_connect_signals(builder, NULL);

    g_object_unref(builder);

    gtk_widget_show(window);                
    gtk_main();

    return 0;
}


// I have to put (extern "C" G_MODULE_EXPORT ) because without  give Could not find signal handler 'on_ok_button_clicked'.  Did you compile with -rdynamic?

extern "C" G_MODULE_EXPORT void on_ok_button_clicked(GtkButton *msgbox_ok, GtkEntry *origin, GtkEntry *target, gpointer user_data)
{



        const gchar *OriginText;
        const gchar *TargetText;

        OriginText = gtk_entry_get_text (GTK_ENTRY (origin)); // gtk_entry_get_text: assertion 'GTK_IS_ENTRY (entry)' failed

        TargetText = OriginText;

        void gtk_entry_set_text (GtkEntry *target, const gchar *TargetText); //Give no action like no command exist




}
extern "C" G_MODULE_EXPORT void on_cancel_button_clicked(GtkButton *cancel_button, gpointer user_data)
{
    gtk_main_quit();
}
extern "C" G_MODULE_EXPORT void on_TestWin_destroy(GtkWidget *TestWin, gpointer user_data)
{

        gtk_main_quit();
}

Файл test.glade в XML creato con Glade 3

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
  <requires lib="gtk+" version="3.20"/>
  <object class="GtkWindow" id="TestWin">
    <property name="can_focus">False</property>
    <property name="default_width">420</property>
    <property name="default_height">200</property>
    <signal name="destroy" handler="on_TestWin_destroy" swapped="no"/>
    <child>
      <placeholder/>
    </child>
    <child>
      <object class="GtkFixed">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <child>
          <object class="GtkButton" id="ok_button">
            <property name="label" translatable="yes">OK</property>
            <property name="width_request">95</property>
            <property name="height_request">35</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="receives_default">True</property>
            <signal name="clicked" handler="on_ok_button_clicked" swapped="no"/>
          </object>
          <packing>
            <property name="x">190</property>
            <property name="y">130</property>
          </packing>
        </child>
        <child>
          <object class="GtkButton" id="cancel_button">
            <property name="label" translatable="yes">Cancell</property>
            <property name="width_request">100</property>
            <property name="height_request">35</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="receives_default">True</property>
            <signal name="clicked" handler="on_cancel_button_clicked" swapped="no"/>
          </object>
          <packing>
            <property name="x">300</property>
            <property name="y">130</property>
          </packing>
        </child>
        <child>
          <object class="GtkEntry" id="origin">
            <property name="width_request">300</property>
            <property name="height_request">35</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
          </object>
          <packing>
            <property name="x">100</property>
            <property name="y">20</property>
          </packing>
        </child>
        <child>
          <object class="GtkEntry" id="target">
            <property name="width_request">300</property>
            <property name="height_request">35</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
          </object>
          <packing>
            <property name="x">100</property>
            <property name="y">60</property>
          </packing>
        </child>
        <child>
          <object class="GtkLabel" id="lbl_origin">
            <property name="width_request">90</property>
            <property name="height_request">35</property>
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="label" translatable="yes">Origin Text</property>
          </object>
          <packing>
            <property name="x">5</property>
            <property name="y">20</property>
          </packing>
        </child>
        <child>
          <object class="GtkLabel" id="lbl_target">
            <property name="width_request">90</property>
            <property name="height_request">35</property>
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="label" translatable="yes">Target Text</property>
          </object>
          <packing>
            <property name="x">5</property>
            <property name="y">60</property>
          </packing>
        </child>
      </object>
    </child>
  </object>
</interface>

Используемая командадля компиляции под Windows 10

gcc  -pthread -mms-bitfields -IC:/msys64/mingw64/include/gtk-3.0 -IC:/msys64/mingw64/include/cairo -IC:/msys64/mingw64/include -IC:/msys64/mingw64/include/pango-1.0 -IC:/msys64/mingw64/include/fribidi -IC:/msys64/mingw64/include -IC:/msys64/mingw64/include/atk-1.0 -IC:/msys64/mingw64/include/cairo -IC:/msys64/mingw64/include/pixman-1 -IC:/msys64/mingw64/include -IC:/msys64/mingw64/include/freetype2 -IC:/msys64/mingw64/include -IC:/msys64/mingw64/include/harfbuzz -IC:/msys64/mingw64/include/libpng16 -IC:/msys64/mingw64/include/gdk-pixbuf-2.0 -IC:/msys64/mingw64/include -IC:/msys64/mingw64/lib/libffi-3.2.1/include -IC:/msys64/mingw64/include/glib-2.0 -IC:/msys64/mingw64/lib/glib-2.0/include -IC:/msys64/mingw64/include test.cpp -o test -LC:/msys64/mingw64/lib -lgtk-3 -lgdk-3 -lz -lgdi32 -limm32 -lshell32 -lole32 -Wl,-luuid -lwinmm -ldwmapi -lsetupapi -lcfgmgr32 -lpangowin32-1.0 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lintl -lglib-2.0
...