我目前正在学习Qt,并且我被困在使用多个QWidgets和一个QMainWindow的问题上。将多个QWidets合并为一个QMainWindow
我设置了一个包含2个QWidgets和一个QMainWindow的项目。这是我使用它的想法:根据需要设计两个QWidgets,将它们添加到主窗口对象,将按钮连接到正确的插槽并在需要时切换中心组件。所以我从一个QMainWindow开始,然后添加了两个QWidgets,包括cpp文件,h文件和ui文件。在两个QWidgets中,我添加了一个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.
您可以发布您的代码或一个浓缩版,以它的链接?我很难理解你想要做什么。 – Mitch
我添加了一个链接来源和一些更多的文字,我希望现在更清楚。 – Cheiron