【发布时间】:2013-01-22 22:18:57
【问题描述】:
我目前正在学习 Qt,我被困在使用多个 QWidget 和一个 QMainWindow 的问题上。
我已经建立了一个项目,其中包含 2 个 QWidgets 和一个 QMainWindow。这是我使用它的想法:根据需要设计两个 QWidget,将它们添加到主窗口对象,将按钮连接到正确的插槽并在需要时切换中心小部件。所以我从一个 QMainWindow 开始,然后添加了两个 QWidget,包括 cpp 文件、h 文件和 ui 文件。在两个 QWidget 上,我添加了一个 QPushButton,并将其命名为 pushButtonConvert。
然后我转到附加到 QMainWindow (mainwindow.cpp) 的 cpp 文件并执行以下操作:
EpochToHuman * epochToHuman = new EpochToHuman();
HumanToEpoch * humanToEpoch = new HumanToEpoch();
到目前为止,一切都很好。现在我想将按钮连接到主窗口对象中的插槽,但我找不到按钮。 epochToHuman->pushButtonConvert 似乎不存在,我找不到任何其他方式来获取按钮。那么,根据 Qt,我是在以一种不正确的方式思考还是我遗漏了什么?
再次尝试澄清我想要的内容: 我想在 QMainWindows 的 cpp 文件中使用 QWidget 中的元素。我希望能够做这样的事情:
//In object MainWindow.cpp
QWidget * a = new QWidget
//Let's say a is a custom widget with a label in it. This label is called Label
a->Label->setText("Hello, World!");
//This gives an error because a does not have a member called Label
//How can I change the text on the label of a?
//And I think if I will be able to change the text of this label, I will also be able to dance around with buttons as needed.
【问题讨论】:
-
您可以发布您的代码的精简版或指向它的链接吗?我很难理解你想要做什么。
-
我添加了一个指向源的链接和一些更多的文字,我希望现在更清楚了。
标签: c++ qt4 qwidget qmainwindow