Qt 无法访问在设计器中创建的 ui 元素 [英] Qt can't acces ui element created in designer
问题描述
我在 Qt 设计器中创建了一个 QComboBox
.现在我想在我的 mainwidget
中访问那个 QComboBox
.但是当创建者无法识别 ui->comboboxName
时.可能有一个简单的解决方案,但我似乎找不到.
I created a QComboBox
in the Qt designer. Now I want to access that QComboBox
in my mainwidget
. But when the creator does not recognize ui->comboboxName
. There is probably an easy solution but I can't seem to find one.
这是我的ui文件中的QCombobox
,在widget的header或者widget的源码中都无法访问rolKeuze
This is the QCombobox
in my ui file, and I can't access rolKeuze in the header of the widget or in the source of the widget
<widget class="QComboBox" name="rolKeuze">
<item>
<property name="text">
<string>Bouwmeester</string>
</property>
</item>
<item>
<property name="text">
<string>Burgemeester</string>
</property>
</item>
</widget>
推荐答案
首先告诉我们你得到的错误.
First tell us the error you get.
还要检查 ui 成员是否是指向 ui 生成代码的指针(它可能是一个对象,您需要 ui.comboboxName
),有时工具没有检测修改后的 .ui 文件,如果是这种情况,请不要为新的添加小部件重新生成 C++ 代码,请使用运行 qmake 然后构建您的项目.
Also check if ui member is an pointer to the ui generated code (it might be an object and you need ui.comboboxName
) and sometimes the tools don't detect the modified .ui file and don't re-generate the c++ code for your new add widgets if that's the case use run qmake and than build your project.
这篇关于Qt 无法访问在设计器中创建的 ui 元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!