01
Июл
2022

В чем проблема? Что-то нужно исправить, дополнить?

Пишу калькулятор. Во время компиляции произошла ошибка, хотя вроде сделал все правильно. Сама ошибка: main.c:26:12: предупреждение: assignment to «GtkEntry *» {aka «struct _GtkEntry *»} from incompatible pointer type «GtkWidget *» {aka «struct _GtkWidget *»} [-Wincompatible-pointer-types]

#include <stdlib.h>
#include <gtk/gtk.h>
#include <string.h>
GtkBuilder *builder;
GtkWidget *window;
GtkEntry  *entry1;
GtkEntryBuffer *entrybuffer1;
gint num1, exp1, epx2, result;
char OP;


int main (int argc, char *argv[])
{
    /* initialize GTK+ */
    g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, (GLogFunc) gtk_false, NULL);
    gtk_init (&argc, &argv);
    g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, g_log_default_handler, NULL);

    builder = gtk_builder_new();
    gtk_builder_add_from_file(builder, "calculator.glade", NULL);
    window = GTK_WIDGET(gtk_builder_get_object(builder, "Window1"));
    g_signal_connect(window, "destroy", gtk_main_quit, NULL);
    gtk_builder_connect_signals(builder, NULL);

    entry1 = GTK_WIDGET(gtk_builder_get_object(builder, "entry1"));
    gtk_entry_set_alignment(entry1, 1);
    entrybuffer1 = gtk_entry_get_buffer(GTK_ENTRY(entry1));

    g_object_unref(builder);
    gtk_widget_show_all (window);
    gtk_main ();
    return 0;
}
G_MODULE_EXPORT void on_button0_clicked(GtkButton *button0, gpointer *data)
{
    const gchar *num = gtk_entry_get_text(GTK_ENTRY(entry1));
    num1 = atoi(num);
    if (num1 == 0)
    {
        gtk_entry_set_text(entry1, "0");
    }
    else
    {
        gtk_entry_buffer_insert_text(entrybuffer1, -1, "0", -1);
    }
}
G_MODULE_EXPORT void on_button1_clicked(GtkButton *button1, gpointer *data)
{
    const gchar *num = gtk_entry_get_text(GTK_ENTRY(entry1));
    num1 = atoi(num);
    if (num1 == 0)
    {
        gtk_entry_set_text(entry1, "1");
    }
    else
    {
        gtk_entry_buffer_insert_text(entrybuffer1, -1, "1", -1);
    }
}
    G_MODULE_EXPORT void on_button2_clicked(GtkButton *button2, gpointer *data)
{
    const gchar *num = gtk_entry_get_text(GTK_ENTRY(entry1));
    num1 = atoi(num);
    if (num1 == 0)
    {
        gtk_entry_set_text(entry1, "2");
    }
    else
    {
        gtk_entry_buffer_insert_text(entrybuffer1, -1, "2", -1);
    }
}
    G_MODULE_EXPORT void on_button3_clicked(GtkButton *button3, gpointer *data)
{
    const gchar *num = gtk_entry_get_text(GTK_ENTRY(entry1));
    num1 = atoi(num);
    if (num1 == 0)
    {
        gtk_entry_set_text(entry1, "3");
    }
    else
    {
        gtk_entry_buffer_insert_text(entrybuffer1, -1, "3", -1);
    }
}
    G_MODULE_EXPORT void on_button4_clicked(GtkButton *button4, gpointer *data)
{
    const gchar *num = gtk_entry_get_text(GTK_ENTRY(entry1));
    num1 = atoi(num);
    if (num1 == 0)
    {
        gtk_entry_set_text(entry1, "4");
    }
    else
    {
        gtk_entry_buffer_insert_text(entrybuffer1, -1, "4", -1);
    }
}
G_MODULE_EXPORT void on_button5_clicked(GtkButton *button5, gpointer *data)
{
    const gchar *num = gtk_entry_get_text(GTK_ENTRY(entry1));
    num1 = atoi(num);
    if (num1 == 0)
    {
        gtk_entry_set_text(entry1, "5");
    }
    else
    {
        gtk_entry_buffer_insert_text(entrybuffer1, -1, "5", -1);
    }
}
G_MODULE_EXPORT void on_button6_clicked(GtkButton *button6, gpointer *data)
{
    const gchar *num = gtk_entry_get_text(GTK_ENTRY(entry1));
    num1 = atoi(num);
    if (num1 == 0)
    {
        gtk_entry_set_text(entry1, "6");
    }
    else
    {
        gtk_entry_buffer_insert_text(entrybuffer1, -1, "6", -1);
    }
}
G_MODULE_EXPORT void on_button7_clicked(GtkButton *button7, gpointer *data)
{
    const gchar *num = gtk_entry_get_text(GTK_ENTRY(entry1));
    num1 = atoi(num);
    if (num1 == 0)
    {
        gtk_entry_set_text(entry1, "7");
    }
    else
    {
        gtk_entry_buffer_insert_text(entrybuffer1, -1, "7", -1);
    }
}
G_MODULE_EXPORT void on_button8_clicked(GtkButton *button8, gpointer *data)
{
    const gchar *num = gtk_entry_get_text(GTK_ENTRY(entry1));
    num1 = atoi(num);
    if (num1 == 0)
    {
        gtk_entry_set_text(entry1, "8");
    }
    else
    {
        gtk_entry_buffer_insert_text(entrybuffer1, -1, "8", -1);
    }
}
G_MODULE_EXPORT void on_button9_clicked(GtkButton *button9, gpointer *data)
{
    const gchar *num = gtk_entry_get_text(GTK_ENTRY(entry1));
    num1 = atoi(num);
    if (num1 == 0)
    {
        gtk_entry_set_text(entry1, "9");
    }
    else
    {
        gtk_entry_buffer_insert_text(entrybuffer1, -1, "9", -1);
    }
}
G_MODULE_EXPORT void on_button_plus_clicked(GtkButton *button_plus, gpointer *data)
{
    const gchar *num = gtk_entry_get_text(GTK_ENTRY(entry1));
    exp1 = atoi(num);
    OP = '+';
    gtk_entry_set_text(entry1, "0");
}
G_MODULE_EXPORT void on_button_minus_clicked(GtkButton *button_minus, gpointer *data)
{
    const gchar *num = gtk_entry_get_text(GTK_ENTRY(entry1));
    exp1 = atoi(num);
    OP = '-';
    gtk_entry_set_text(entry1, "0");
}
G_MODULE_EXPORT void on_button_multi_clicked(GtkButton *button_multi, gpointer *data)
{
    const gchar *num = gtk_entry_get_text(GTK_ENTRY(entry1));
    exp1 = atoi(num);
    OP = '*';
    gtk_entry_set_text(entry1, "0");
}
G_MODULE_EXPORT void on_button_div_clicked(GtkButton *button_div, gpointer *data)
{
    const gchar *num = gtk_entry_get_text(GTK_ENTRY(entry1));
    exp1 = atoi(num);
    OP = '/';
    gtk_entry_set_text(entry1, "0");
}
G_MODULE_EXPORT void on_Window1_destroy(GtkAction *action)
{
    gtk_main_quit();
}
G_MODULE_EXPORT void on_button_clear_clicked(GtkButton *button_clear, gpointer *data)
{

    gtk_entry_set_text(entry1, "0");
}
G_MODULE_EXPORT void on_button_result_clicked(GtkButton *button_result, gpointer *data)
{
    const gchar *num = gtk_entry_get_text(GTK_ENTRY(entry1));
    epx2 = atoi(num);
    switch (OP)
    {
    case '+':
        result = exp1 + epx2;
    break;
    case '-':
        result = exp1 - epx2;
    break;
    case '*':
        result = exp1 * epx2;
    break;
    case '/':
        result = exp1 / epx2;
    break;
    }
    char* result_string = malloc(sizeof(char) * 10);
    memset(result_string, 0, 10);
    sprintf(result_string, "%d", result);
    gtk_entry_set_text(GTK_ENTRY(entry1), result_string);
}

Источник: https://ru.stackoverflow.com/questions/1425858/%D0%92-%D1%87%D0%B5%D0%BC-%D0%BF%D1%80%D0%BE%D0%B1%D0%BB%D0%B5%D0%BC%D0%B0-%D0%A7%D1%82%D0%BE-%D1%82%D0%BE-%D0%BD%D1%83%D0%B6%D0%BD%D0%BE-%D0%B8%D1%81%D0%BF%D1%80%D0%B0%D0%B2%D0%B8%D1%82%D1%8C-%D0%B4%D0%BE%D0%BF%D0%BE%D0%BB%D0%BD%D0%B8%D1%82%D1%8C

Тебе может это понравится...

Добавить комментарий