我目前正在學習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