【问题标题】:Error arising when assigning window .load and .unload functions分配窗口 .load 和 .unload 函数时出现错误
【发布时间】:2014-06-10 21:31:27
【问题描述】:

我正在开发一个多窗口应用程序,在我的第二个窗口中,我调用了这个 init() 函数

static struct MessageUI {
    Window *window;
    MenuLayer *menu_layer;
} ui;

...
...
...

void messages_init(void) {
    ui.window = window_create();

    window_set_window_handlers(ui.window, (WindowHandlers) {
        .load = window_load,
        .unload = window_unload
    });
}

当我运行代码时,我收到与 .load 和 .unload 赋值运算符有关的错误。

../src/messages.c: In function 'messages_init':
../src/messages.c:63:3: error: initialization from incompatible pointer type [-Werror]
../src/messages.c:63:3: error: (near initialization for 'handlers.load') [-Werror]
../src/messages.c:65:2: error: initialization from incompatible pointer type [-Werror]
../src/messages.c:65:2: error: (near initialization for 'handlers.unload') [-Werror]

知道为什么会出现这个错误吗?

提前致谢!

编辑

这是我的 window_load 和 window_unload 函数

static void window_load(void) {
    // Create it - 12 is approx height of the top bar
    ui.menu_layer = menu_layer_create(GRect(0,0,144,168-16));
    menu_layer_set_click_config_onto_window(ui.menu_layer,ui.window);

    MenuLayerCallbacks callbacks = { 
        .draw_row = (MenuLayerDrawRowCallback) draw_row_callback,
        .get_num_rows = (MenuLayerGetNumberOfRowsInSectionsCallback) num_rows_callback,
        .select_click = (MenuLayerSelectCallback) select_click_callback
    };
    menu_layer_set_callbacks(ui.menu_layer, NULL, callbacks);

    //Add to window
    layer_add_child(window_get_root_layer(ui.window), menu_layer_get_layer(ui.menu_layer));
}

static void window_unload(void) {
    APP_LOG(APP_LOG_LEVEL_DEBUG, "unloading message UI");
}

【问题讨论】:

  • window_loadwindow_unload 是如何定义的?
  • 我在上面添加了 window_load 和 window_unload 函数。

标签: c pebble-watch pebble-sdk


【解决方案1】:

发生该错误是因为window_loadwindow_unload 都意味着接收指向Window 的指针。你应该这样声明它们:

static void window_load(Window *window) {
    // ...
}

static void window_unload(Window *window) {
    // ...
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-30
    • 2018-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多