私は現在Qtを学習していますが、複数のQWidgetsと1つのQMainWindowを使用するという問題に悩まされています。
2つのQWidgetsと1つのQMainWindowを含むプロジェクトをセットアップしました。これは私の考えです。必要に応じて両方のQWidgetsを設計し、それらをメインウィンドウオブジェクトに追加し、ボタンを正しいスロットに接続し、必要に応じてcenterwidgetを切り替えます。そこで、1つのQMainWindowから始めて、cppファイル、hファイル、およびuiファイルを含む2つのQWidgetを追加しました。両方のQWidgetsに1つの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.