QT通过 QT designer 可以生成 ui文件

  1. .生成方式:QT通过 QT designer 可以生成 ui文件  (.ui  && .ui.h)

  2. 2.UI文件内容: 以XML方式记录了QT designer生成的界面的相关内容,大体可以分为如下内容


  3. widget属性,其内容(图形元素, layout。。)的相关属性

  4. 头文件     

  5. 变量

  6. 槽 


  7. 函数

  8. 3. 通过UIC  (user interface compiler)可以把UI文件内容翻译成标准.h, .cpp文件

  9. uic使用方法:


  10. 生成声明(.h)文件:    uic [options] <file>  


  11. uic  [options] -subdecl <classname> <headerfile> <file>生成实现(.cpp)文件:uic [options] -impl <headerfile> <file>

  12. uic  [options] -subimpl <classname> <headerfile> <file选项:


  13. -o file - write output to 'file' rather than to stdout. 

  14. -nofwd - omit forward declarations of custom classes in the generated header file. This is necessary if typedef classes are used. 

  15. -tr func - use func(sourceText, comment) rather than trUtf8(sourceText, comment) for internationalization. 

  16. 4.使用: (IN Makefile)


  17.     %.h: %.ui        uic $< -o $@    %.cpp: %.ui        uic -impl $*.h $< -o $@注:

  18. .ui.h 文件包含ui文件功能实现部分(slot,function,include,variable)

  19. 更改.ui.h文件后(如:加入一个槽),可能.ui文件没有做自动改变,这样会导致编译失败,需手动更改.ui文件

  20. QT 的Makefile会根据.ui文件生成相应源代码,而不是.ui.h文件


  21. 5.更改 .ui文件中的中文(.ui文件中中文为utf8, vi中显示不正常)

  22.     iconv  -f utf8 -t gbk  input.ui > output.ui.gbk

  23.     vi  output.ui.gbk

  24.     iconv  -f gbk -t utf8 output.ui.gbk > input.ui