免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 7037 | 回复: 14
打印 上一主题 下一主题

linux下编程,一定要学gtk,qt这些图形编程吗? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-07-15 21:17 |只看该作者 |正序浏览
linux下的图形编程很重要吗?感觉linux的强势在网络,图形做着有前途吗?都有哪些应用?
gtk qt如何选择?

论坛徽章:
0
15 [报告]
发表于 2009-07-16 18:30 |只看该作者
我到现在还没做过linux下的图形编程,主要是目前还用不上。感觉linux的优势还是在于嵌入式方面

论坛徽章:
24
狮子座
日期:2013-12-31 10:48:0015-16赛季CBA联赛之吉林
日期:2016-04-18 14:43:1015-16赛季CBA联赛之北控
日期:2016-05-18 15:01:4415-16赛季CBA联赛之上海
日期:2016-06-22 18:00:1315-16赛季CBA联赛之八一
日期:2016-06-25 11:02:2215-16赛季CBA联赛之佛山
日期:2016-08-17 22:48:2615-16赛季CBA联赛之福建
日期:2016-12-27 22:39:272016科比退役纪念章
日期:2017-02-08 23:49:4315-16赛季CBA联赛之八一
日期:2017-02-16 01:05:3415-16赛季CBA联赛之山东
日期:2017-02-22 15:34:5615-16赛季CBA联赛之上海
日期:2017-11-25 16:17:5015-16赛季CBA联赛之四川
日期:2016-01-17 18:38:37
14 [报告]
发表于 2009-07-16 18:04 |只看该作者

回复 #1 cskyrain 的帖子

你们公司要用 gtk ,是哪家公司我很好奇,很少有公司需要做 Linux 界面。

gtk 教程参见:http://library.gnome.org/devel/gtk-tutorial/stable/book1.html  

Hello World in GTK,看懂这个就算入门:

#include <gtk/gtk.h>

/* This is a callback function. The data arguments are ignored
&nbsp;* in this example. More on callbacks below. */

static void hello( GtkWidget *widget,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gpointer   data )
{
&nbsp;&nbsp;&nbsp;&nbsp;g_print ("Hello World\n");
}

static gboolean delete_event( GtkWidget *widget,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GdkEvent  *event,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gpointer   data )
{
&nbsp;&nbsp;&nbsp;&nbsp;/* If you return FALSE in the "delete_event" signal handler,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* GTK will emit the "destroy" signal. Returning TRUE means
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* you don't want the window to be destroyed.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* This is useful for popping up 'are you sure you want to quit?'
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* type dialogs. */


&nbsp;&nbsp;&nbsp;&nbsp;g_print ("delete event occurred\n");

&nbsp;&nbsp;&nbsp;&nbsp;/* Change TRUE to FALSE and the main window will be destroyed with
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* a "delete_event". */


&nbsp;&nbsp;&nbsp;&nbsp;return TRUE;
}

/* Another callback */
static void destroy( GtkWidget *widget,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gpointer   data )
{
&nbsp;&nbsp;&nbsp;&nbsp;gtk_main_quit ();
}

int main( int   argc,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;char *argv[] )
{
&nbsp;&nbsp;&nbsp;&nbsp;/* GtkWidget is the storage type for widgets */
&nbsp;&nbsp;&nbsp;&nbsp;GtkWidget *window;
&nbsp;&nbsp;&nbsp;&nbsp;GtkWidget *button;
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;/* This is called in all GTK applications. Arguments are parsed
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* from the command line and are returned to the application. */

&nbsp;&nbsp;&nbsp;&nbsp;gtk_init (&argc, &argv);
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;/* create a new window */
&nbsp;&nbsp;&nbsp;&nbsp;window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;/* When the window is given the "delete_event" signal (this is given
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* by the window manager, usually by the "close" option, or on the
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* titlebar), we ask it to call the delete_event () function
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* as defined above. The data passed to the callback
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* function is NULL and is ignored in the callback function. */

&nbsp;&nbsp;&nbsp;&nbsp;g_signal_connect (G_OBJECT (window), "delete_event",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;      G_CALLBACK (delete_event), NULL);
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;/* Here we connect the "destroy" event to a signal handler.  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* This event occurs when we call gtk_widget_destroy() on the window,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* or if we return FALSE in the "delete_event" callback. */

&nbsp;&nbsp;&nbsp;&nbsp;g_signal_connect (G_OBJECT (window), "destroy",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;      G_CALLBACK (destroy), NULL);
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;/* Sets the border width of the window. */
&nbsp;&nbsp;&nbsp;&nbsp;gtk_container_set_border_width (GTK_CONTAINER (window), 10);
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;/* Creates a new button with the label "Hello World". */
&nbsp;&nbsp;&nbsp;&nbsp;button = gtk_button_new_with_label ("Hello World");
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;/* When the button receives the "clicked" signal, it will call the
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* function hello() passing it NULL as its argument.  The hello()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* function is defined above. */

&nbsp;&nbsp;&nbsp;&nbsp;g_signal_connect (G_OBJECT (button), "clicked",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;      G_CALLBACK (hello), NULL);
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;/* This will cause the window to be destroyed by calling
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* gtk_widget_destroy(window) when "clicked".  Again, the destroy
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* signal could come from here, or the window manager. */

&nbsp;&nbsp;&nbsp;&nbsp;g_signal_connect_swapped (G_OBJECT (button), "clicked",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;      G_CALLBACK (gtk_widget_destroy),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;G_OBJECT (window));
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;/* This packs the button into the window (a gtk container). */
&nbsp;&nbsp;&nbsp;&nbsp;gtk_container_add (GTK_CONTAINER (window), button);
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;/* The final step is to display this newly created widget. */
&nbsp;&nbsp;&nbsp;&nbsp;gtk_widget_show (button);
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;/* and the window */
&nbsp;&nbsp;&nbsp;&nbsp;gtk_widget_show (window);
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;/* All GTK applications must have a gtk_main(). Control ends here
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* and waits for an event to occur (like a key press or
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* mouse event). */

&nbsp;&nbsp;&nbsp;&nbsp;gtk_main ();
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;return 0;
}

论坛徽章:
0
13 [报告]
发表于 2009-07-16 17:10 |只看该作者

回复 #7 鬼才小科 的帖子

谢谢你的回复,不过这个真的是我现在遇到得问题,新入职,发现要做gtk方面的开发,以前一直看网络方面的东西,不知所措了。

论坛徽章:
0
12 [报告]
发表于 2009-07-16 12:53 |只看该作者

回复 #12 nizvoo 的帖子

做Linux下编程的人,大部分都不做界面的吧

论坛徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:56:11
11 [报告]
发表于 2009-07-16 11:06 |只看该作者
学点好,至少能做点简单界面

论坛徽章:
24
狮子座
日期:2013-12-31 10:48:0015-16赛季CBA联赛之吉林
日期:2016-04-18 14:43:1015-16赛季CBA联赛之北控
日期:2016-05-18 15:01:4415-16赛季CBA联赛之上海
日期:2016-06-22 18:00:1315-16赛季CBA联赛之八一
日期:2016-06-25 11:02:2215-16赛季CBA联赛之佛山
日期:2016-08-17 22:48:2615-16赛季CBA联赛之福建
日期:2016-12-27 22:39:272016科比退役纪念章
日期:2017-02-08 23:49:4315-16赛季CBA联赛之八一
日期:2017-02-16 01:05:3415-16赛季CBA联赛之山东
日期:2017-02-22 15:34:5615-16赛季CBA联赛之上海
日期:2017-11-25 16:17:5015-16赛季CBA联赛之四川
日期:2016-01-17 18:38:37
10 [报告]
发表于 2009-07-16 10:31 |只看该作者
原帖由 cskyrain 于 2009-7-15 21:17 发表
linux下的图形编程很重要吗?感觉linux的强势在网络,图形做着有前途吗?都有哪些应用?
gtk qt如何选择?



你可以在程序里内置一个 web 服务器提供 http 服务,把界面显示交给浏览器处理,我见过好几个这样的程序。

论坛徽章:
0
9 [报告]
发表于 2009-07-16 10:19 |只看该作者
java? 还不如Mono呢

论坛徽章:
0
8 [报告]
发表于 2009-07-16 10:02 |只看该作者
不同方向,楼主弄混了

论坛徽章:
0
7 [报告]
发表于 2009-07-16 10:00 |只看该作者
楼主问这个问题显示就是来骗分的,因为这个问题就像:人要活必须吃海鲜吗? 所以依据jobnbull的逻辑此帖子是非恶意灌水,应该封贴。

PS:请注意是小写,不同于JohnBull。请不要对号入座。谢谢。
  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP