Tanky WooRSS

Qt demo — 3.Calculator Builder

10 Jun 2011
这篇博客是从旧博客 WordPress 迁移过来,内容可能存在转换异常。

要抓狂了,上次片的Qt demo--2是在3月份写的,这都6月份了~~~

好久没学Qt了,加油啊!

这个例子是在demo的/Qt Designer/Calculator Builder中,主要是介绍QUiLoader class,按照上面的介绍,就是:shows how to create a user interface from a Qt Designer from at run-time, using the QUiLoader class.

Show一下运行结果图:

demo_3_2

1.QINITRESOURCE Initializes the resources specified by the .qrc file with the specified base name. Normally, Qt resources are loaded automatically at startup. The QINITRESOURCE() macro is necessary on some platforms for resources stored in a static library.

这在上一篇也写过的。

2.这里使用了QUiLoader机制,使UI与内部开发分离。

上午还在网上找了一篇非常详细的讲解,而且这篇讲解基本就是根据这个例子来的:

http://www.wutianqi.com/?p=2591

3.QUiLoader就是载入一个.ui文件(这个.ui被当作一个资源文件使用),然后使用这个UI,当然,这个UI的设计就不关我的事了。

demo_3_3

这个是.ui文件打开后的样子:

demo_3_1

4.记得包含头文件:

demo_3_7

5.这一段就是QUiLoader机制了:

demo_3_4

6.如果相对UI中的元素进行进一步处理,可以通过qFindChild来找到,并处理:

demo_3_5

7.元对象的自动连接信号和槽,在上面转载的那篇文章里具体讲到了:

demo_3_6

源码自己在安装的Qt中找,就不给出了。