C++ Qt - setupUi()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5692991/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 18:40:53  来源:igfitidea点击:

Qt - setupUi( )

c++user-interfaceqt4

提问by Simplicity

Possible Duplicate:
Qt - initializing the form

可能的重复:
Qt - 初始化表单

I tried to look for a description for the setupUi()method but couldn't find especially in the Qtdocumentation.

我试图寻找该setupUi()方法的描述,但在Qt文档中尤其找不到。

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?

这个方法有什么作用?例如,如果我在 class 中写作setupUi(this),这会做什么?最后设置用户界面意味着什么?

Thanks.

谢谢。

回答by Barbaris

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:

setupUi()为您创建小部件的实际实例。您在 QtDesigner 中创建的表单存储为 XML 文件。因此,为了能够使用您在 QtDesigner 中放置的所有元素构建实际的“窗口”并将其显示在您的应用程序中,setupUi()UIC(UI 编译器 - Qt 工具)会自动为您创建,因此您没有手动执行此操作。您在 QtDesigner 中设置的所有属性以及放置在那里的所有元素都将在 C++ 代码中进行“翻译”,如下所示:

QLabel *label1 = new QLabel(tr("Start"), this);
QTableView *view1 = new QTableView(this);
...