Hi,
I’m writing an app to try get back on coding, strugguling because i mostly have experience on very different type of coding and it was years ago.
so far, my app can load a text file and count the number of words in the textview. i tried to add an AdwPreferencesDialog following the way it is implemented in the libadwaita demo (adw-demo-preferences-dialog.h and adw-demo-preferences-dialog.c),
counter-preferences.h :
#pragma once
#include <adwaita.h>
G_BEGIN_DECLS
#define COUNTER_TYPE_PREFERENCES (counter_preferences_get_type())
G_DECLARE_FINAL_TYPE (CounterPreferences, counter_preferences, COUNTER, PREFERENCES_DIALOG, AdwPreferencesDialog)
AdwDialog *counter_preferences_new (void);
G_END_DECLS
counter-preferences.c :
#include “counter-preferences.h”
struct _CounterPreferences
{
AdwPreferencesDialog parent_instance;
};G_DEFINE_FINAL_TYPE (CounterPreferences, counter_preferences, COUNTER_TYPE_PREFERENCES)
static void
counter_preferences_class_init (CounterPreferencesClass *klass)
{
g_printerr (“class init”);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);gtk_widget_class_set_template_from_resource (widget_class, “/org/nabil/Counter/preferences.ui”);
}static void
counter_preferences_init (CounterPreferences *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
}AdwDialog *
counter_preferences_new (void)
{
return g_object_new (COUNTER_TYPE_PREFERENCES, NULL);
}
my app compile but when i try to open the preferences from the button in the primary menu, it freeze.
In counter-application here is how i initialize it :
static void
counter_application_preferences_action (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{GtkApplication *app = GTK_APPLICATION (user_data);
GtkWindow *window = gtk_application_get_active_window (app);adw_dialog_present (counter_preferences_new (), GTK_WIDGET (window));
}static void
counter_application_quit_action (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
CounterApplication *self = user_data;g_assert (COUNTER_IS_APPLICATION (self));
g_application_quit (G_APPLICATION (self));
}static const GActionEntry app_actions = {
{ “quit”, counter_application_quit_action, NULL, NULL, NULL },
{ “preferences”, counter_application_preferences_action, NULL, NULL, NULL },
{ “about”, counter_application_about_action, NULL, NULL, NULL },
};static void
counter_application_init (CounterApplication *self)
{
g_action_map_add_action_entries (G_ACTION_MAP (self),
app_actions,
G_N_ELEMENTS (app_actions),
self);gtk_application_set_accels_for_action (GTK_APPLICATION (self),
“app.quit”,
(const char *) {
“q”,
NULL
});}
I have no idea why the crash goes or how to debug it. By using g_printerr messages i figured out that the app crash in counter-preferences.c when calling the new function that returns the result of g_object_new :
AdwDialog *
counter_preferences_new (void)
{
return g_object_new (COUNTER_TYPE_PREFERENCES, NULL);
}
thank you in advance for your help