问题描述
可能的重复:
Qt - 初始化表单
我试图寻找 setupUi()
方法的描述,但在 Qt
文档中尤其找不到.
I tried to look for a description for the setupUi()
method but couldn't find especially in the Qt
documentation.
这个方法有什么作用?例如,如果我在类 setupUi(this)
中编写,这会做什么?设置用户界面最终意味着什么?
What does this method do? For example, if I write in a class setupUi(this)
, what will this do? What does setting up a user interface mean at the end?
谢谢.
推荐答案
setupUi()
为您创建小部件的实际实例.您在 QtDesigner 中创建的表单存储为 XML 文件.因此,为了能够使用您在 QtDesigner 中放置的所有元素构建实际的窗口"并将其显示在您的应用程序中,setupUi()
由 UIC(UI 编译器 -Qt 工具),因此您不必手动执行此操作.您在 QtDesigner 中设置的所有属性以及放置在那里的所有元素都将在 C++ 代码中进行翻译",如下所示:
setupUi()
creates the actual instances of widgets for you. A form that you create in QtDesigner is stored just as XML file. So to be able to build the actual "window" with all the elements that you put on it in QtDesigner and display it in your application, setupUi()
is created for you automatically by UIC (UI compiler - a Qt tool) so you don't have to do that manually. All the properties that you set in QtDesigner and all elements you put there will be "translated" in C++ code like this:
QLabel *label1 = new QLabel(tr("Start"), this);
QTableView *view1 = new QTableView(this);
...
这篇关于Qt - setupUi()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!