GTK项目成功编译。但是没有用

时间:2015-12-21 18:49:09

标签: c gtk gtk3

我正在尝试为我的Raspberry PI项目编写简单的gtk3 GUI。我开始用Eclipse C / C ++编写一些文章,一旦我使用Eclipse,一切都像魅力一样。当我决定编译主代码本身时,它会编译,但输出文件不想启动。我在Ubuntu上有权限被拒绝错误。当Eclipse运行时,我转到Projectsourcefolder / Debug / main并运行它,它再次运行,但是当我尝试运行gcc编译版本时,它没有。亲爱的,你知道为什么吗?

#include <gtk/gtk.h>

static void print_hello (GtkWidget *widget, gpointer data){
  printf("Hello World\n");
}

static void activate(GtkApplication *app, gpointer user_data){
  GtkWidget *window;
  GtkWidget *grid;
  GtkWidget *button;
  GtkWidget *image;

  window = gtk_application_window_new (app);
  gtk_window_set_title (GTK_WINDOW (window), "Generator");
  gtk_container_set_border_width (GTK_CONTAINER (window), 10);

  grid = gtk_grid_new ();

  gtk_container_add (GTK_CONTAINER (window), grid);

  button = gtk_button_new();
  image = gtk_image_new_from_file("Grafiki/sinus.png");
  gtk_button_set_image(GTK_BUTTON(button), image);
  g_signal_connect (GTK_BUTTON(button), "clicked", G_CALLBACK (print_hello), NULL);

  gtk_grid_attach (GTK_GRID (grid), GTK_BUTTON(button), 0, 0, 1, 1);

  button = gtk_button_new();
  image = gtk_image_new_from_file("Grafiki/square.png");
  gtk_button_set_image(GTK_BUTTON(button), image);
  g_signal_connect (GTK_BUTTON(button), "clicked", G_CALLBACK (print_hello), NULL);

  gtk_grid_attach (GTK_GRID (grid), GTK_BUTTON(button), 1, 0, 1, 1);

  button = gtk_button_new_with_label ("Quit");
  g_signal_connect_swapped (GTK_BUTTON(button), "clicked", G_CALLBACK (gtk_widget_destroy), window);

  gtk_grid_attach (GTK_GRID (grid), GTK_BUTTON(button), 0, 1, 2, 1);

  gtk_window_set_default_size (GTK_WINDOW (window), 480, 320);
  gtk_widget_show_all (window);

}

int main (int argc, char **argv){
  GtkApplication *app;
  int status;

  app = gtk_application_new ("org.gtk.Generator", G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  status = g_application_run(G_APPLICATION (app), argc, argv);
  g_object_unref (app);

  return status;
}

0 个答案:

没有答案