Creator中推广小部件

Creator中推广小部件

本文介绍了在Qt Creator中推广小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Qt创建者可以选择将一个窗口小部件升级为从基础窗口小部件派生的自定义类-我想使用它来将窗口小部件提升为当前项目中的类. Qt创建者问我有关类名和头文件名的信息,这些值直接进入 *.ui 文件,然后进入 ui_myform.h -问题是该文件可能是(通常是)在可位于任意位置的源树(在构建树中)之外生成的,因此直接指定升级窗口中的路径不会有帮助.如何让QtCreator/uic知道在哪里寻找正确的标题?甚至有可能吗?

Qt creator has option to promote one widget to customly created class that derives from base widget - I want to use that to promote widget to class in current project. Qt creator asks me about class name and header filename, and those value go directly to *.ui file, and then to ui_myform.h - the problem is that this file might be (and usually is) generated outside source tree (in build tree) which can be at arbitrary location, so direct specification of path in promoting window will not help. How to let QtCreator/uic know where to look for right header? Is it even possible?

也许源树中有一些Qt变量指定位置,我可以将其插入标头文件名字段中?

Perhaps there is some Qt variable specyfying location of source tree, that I could insert in header filename field?

我正在使用自编译的QtCreator 2.0.1 +自编译的Qt 4.7.1.

I am using self-compiled QtCreator 2.0.1 + self-compiled Qt 4.7.1.

如果我要移动源代码树,或者甚至在网络上共享它-那么每个想要编译我的项目的人都必须在Qt创建者或源文件中编辑此路径-都不可接受.

What if I will move source tree, or even share it on the web - then everybody who wants to compile my project would have to edit this path either in Qt creator or in source files - both are unacceptable.

推荐答案

Designer在升级对话框中要求您提供的头文件是您的自己的头文件,该头文件定义了自定义窗口小部件,而不是生成的 ui _ *.h 文件.

The header file that Designer asks you for in the promotion dialog is YOUR own header file that define the custom widget, not the generated ui_*.h file.

假设您要将普通的QWidget升级为MyCustomWidget,则必须已经有一个 MyCustomWidget.h 定义了 .pro中包含的MyCustomWidget类. em>像这样的文件:

Say you want to promote a plain QWidget to MyCustomWidget, you must already have a MyCustomWidget.h that defines your MyCustomWidget class included in your .pro file like this:

HEADERS  += MyCustomWidget.h

然后在小部件升级对话框中,输入 MyCustomWidget.h .这样做的目的是使生成的ui头文件(无论位于何处)都可以包含您的类定义.

And in the widget promotion dialog, just type in MyCustomWidget.h. The purpose of it is so the generated ui header file (wherever it is) can include YOUR class definition.

这篇关于在Qt Creator中推广小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 02:51