Qt Designer 生成 C++ 代码 [英] Qt Designer generate C++ code

查看:199
本文介绍了Qt Designer 生成 C++ 代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用 Qt 设计器查看 C++ 代码?我可以绘制我的界面并将其保存为 .ui 文件.此外,我可以使用 .bat 文件从 .ui 文件生成 python 代码.但是我无法查看从 UI 生成的 C++/Qt 代码,这是我想要的.

Is it possible to see C++ code with Qt Designer ? I can draw my interface and have it saved as a .ui file. Also, I can generate python code from .ui file using a .bat file. But I cannot view C++/Qt code generated from the UI, which I would like to get.

我找过了,我能找到的只有 doc.关于如何从 .ui 生成 python,我可以做但不是我想要的.

I looked for it and all I can find is doc. about how to generate the python from the .ui, which I can do but is not what I am looking for.

谢谢

推荐答案

菜单项Form/View Code"正是您所期望的 - 它显示了生成的 C++ 代码:

The menu item "Form/View Code" is exactly what you expect - it shows the generated C++ code:

从生成文件的注释中可以看出,Qt 设计器还使用了 uic(Qt 用户界面编译器) 生成代码预览.

As you can see from the comments in the generated file, Qt designer also uses uic (the Qt User Interface Compiler) to generate the code preview.

您可以通过手动创建源代码来验证 uic 是否正常工作:

You can verify if uic works properly by manually creating the source code:

  • 将您的表单保存到 .ui 文件,例如sample.ui
  • 从命令外壳运行 uic -o sample.h sample.ui
  • sample.h 然后包含生成的源代码
  • save your form to a .ui file, e.g. sample.ui
  • Run uic -o sample.h sample.ui from a command shell
  • sample.h then contains the generated source code

这篇关于Qt Designer 生成 C++ 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆