paip.c语言gtk开发环境CodeBlocks /QT建立最佳实践
作者Attilax , EMAIL:1466519819@qq.com
来源:attilax的专栏
地址:http://blog.csdn.net/attilax
1.工具准备:
//
ide: CodeBlocks 12.11 (28M).... 当然也能使用强大的QT
界面设计器: glade-3-14-2-installer.exe
2.新的建立一个gtk项目
///
中间需要选择gtk sdk路径,,D:\gtk+bundle_2.24.10-20120208_win32del
3.建立一个界面使用glade-3-14-2
/
保存的时候保存gtkbuilder格式..还有老的libglade格式 也能了..
自 gtk 的版本升到 2.12,它就包含了 GtkBuilder .GtkBuilder 的作用和 libglade 一样,用来加载 glade 文件,
4.加入源码
//
#include <stdlib.h>
#include <gtk/gtk.h>
#include <glade.h>
#include <glib.h>
int main (int argc, char *argv[])
{
gtk_init(&argc, &argv);
GtkBuilder *pBuilder = NULL;
GtkWidget *pMainWindow = NULL;
pBuilder = gtk_builder_new();
GError *err = NULL;
if(0== gtk_builder_add_from_file(pBuilder,"c:/haloc9.gtkfmt",&err))
{
/* Print out the error. You can use GLib's message logging */
fprintf(stderr, "Error adding build from file. Error: %s\n", err->message);
/* Your error handling code goes here */
}
pMainWindow = GTK_WIDGET(gtk_builder_get_object(pBuilder, "window1"));
if (NULL == pMainWindow)
{
/* Print out the error. You can use GLib's message logging */
fprintf(stderr, "Unable to file object with id \"window1\" \n");
/* Your error handling code goes here */
}
gtk_builder_connect_signals (pBuilder, NULL);
printf("aa");
g_object_unref (G_OBJECT (pBuilder));
gtk_widget_show(pMainWindow);
/* Enter the main loop */
gtk_main ();
return 0;
}
/*自 gtk 的版本升到 2.12,它就包含了 GtkBuilde
GladeXML *xml = NULL;
GtkWidget *pMainWindow = NULL;
xml = glade_xml_new ("d:/halo.glade", "app", NULL);
pMainWindow = glade_xml_get_widget (xml, "window1"); //获取控件指针后,便可用gtk代码操作该
*/
/* Create a vertical box with buttons
unknown type name
button = gtk_button_new_from_stock (GTK_STOCK_DIALOG_INFO);
g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (helloWorld), (gpointer) win);
*/
/**/
/*
GtkWidget *window = NULL;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "icon");
gtk_window_set_default_size(GTK_WINDOW(window), 230, 150);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
// gtk_window_set_icon(GTK_WINDOW(window), create_pixbuf("web.png"));
gtk_widget_show(window);
// gtk_widget_show_all (pMainWindow);
*/
5.CodeBlocks设置编译器以及调试器
settting>complier settting>toolchain executables(tab)>>D:\Qt\Qt5.1.1\Tools\mingw48_32
program files(tab) >>c compiler:gcc.exe 以及liker: g++.exe
settting>complier settting>debugger>>D:\Qt\Qt5.1.1\Tools\mingw48_32\bin\gdb.exe
6.运行OK
///
CodeBlocks加入include 以及*.h头文件
//
settting>complier settting>>searching drirection(tabs) >>add a dir..
D:\cworkspace\AtiGtk\main.c|10|error: unknown type name 'GladeXML'|
参考
gtk 图形界面开发步骤(gtk代码和glade xml 图形设计分离) - clydezhou的专栏 - 博客频道 - CSDN.NET.htm
第一个GTK+程序 - Neo E. Cai - 博客园.htm
GtkBuilder的类似软件 - GTK界面开发工具 - 开源中国社区.htm
c - Gtk-Critical gtk_widget_show assertion GTK_IS_WIDGET(WIDGET) - Stack Overflow
GTK+ and Glade3 GUI Programming Tutorial - Part 1.htm