Enum in my application

I have this code:

enums.h

/**
 * FinanceTransactionType
 * @TRANSACTION_CREDIT:
 * @TRANSACTION_DEBIT:
 * 
 */
typedef enum
{
  TRANSACTION_CREDIT,
  TRANSACTION_DEBIT,
}FinanceTransactionType;

my-file.c
.
.
.
properties[TRANSACTION_TYPE] = g_param_spec_enum (“transaction-type”,
“Transaction Type”,
“The Transaction Type”,
G_TYPE_ENUM,
TRANSACTION_CREDIT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

And this error:

(finance:2): GLib-GObject-CRITICAL **: 22:54:26.602: g_param_spec_enum: assertion ‘g_enum_get_value (enum_class, default_value) != NULL’ failed

(finance:2): GLib-GObject-CRITICAL **: 22:54:26.603: validate_pspec_to_install: assertion ‘G_IS_PARAM_SPEC (pspec)’ failed

Can someone explain to me how to implement this property correctly.

You cannot use G_TYPE_ENUM: it is an abstract type to be used as base class for your enums.

In other words, it is not enough to just define your enum: you must implement it as a GObject type, either by hand or (more commonly) by using the glib-mkenums utility. Once done that, you’ll get your enum type (e.g. MY_TYPE_TRANSACTION) that you can use instead of G_TYPE_ENUM.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.