从不兼容的指针类型(C)分配

时间:2013-02-11 03:03:29

标签: c

我的代码如下,rb_gst_get_encoding_profile不会像rec_settings.profile那样返回gchar *。

typedef struct Recording_Settings recording_settings;
struct Recording_Settings
{
    gchar *profile;
    gchar *destination;
};
recording_settings rec_settings;

typedef struct _GstEncodingProfile GstEncodingProfile;
GstEncodingProfile *rb_gst_get_encoding_profile (const char *media_type);

警告:从不兼容的指针类型分配:

rec_settings.profile = gconf_client_get_string(client, "/apps/sound/recording/profile", NULL);
if (!rec_settings.profile)
    rec_settings.profile = g_strdup("audio/x-vorbis");

static void profile_combo_change_cb(GtkComboBox *combo, gpointer userdata)
{
    GtkTreeIter iter;
    GtkTreeModel *model;

    /* Grab the encoding profile choosen */
    model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
    if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter)) {
        gchar *media_type;
        gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &media_type, -1);
        rec_settings.profile = rb_gst_get_encoding_profile(media_type); // Warning: assignment from incompatible pointer type
        g_free (media_type);
    }
}

我尝试修复它们。这样做的方法是什么?

由于

audio_profile_combo = audio_profile_chooser_new();
gchar *media_type;
media_type = rb_gst_encoding_profile_get_media_type(rec_settings.profile); // Warning: assignment from incompatible pointer type
audio_profile_chooser_set_active(audio_profile_combo, media_type);
g_free (media_type);

2 个答案:

答案 0 :(得分:0)

在这一行:

rec_settings.profile = rb_gst_get_encoding_profile(media_type);

media_typegchar *,但函数rb_gst_get_encoding_profile需要const char *。这就是错误的原因。

编辑:更不用说函数本身会返回GstEncodingProfile *,而您正尝试将其分配给rec_settings.profile,即gchar *

答案 1 :(得分:0)

将Recording_Settings结构更改为:

struct Recording_Settings
{
    GstEncodingProfile *profile;
    gchar *destination;
};

至少,这是我应该从现有的小信息中获得的。