When I first looked at the foggy, I understood a little bit now. Now suppose there is a form, a MainWindow, that:
Implement click Pushbutton to transfer the contents of the text box to MainWindow, which is displayed as a label. I have drawn the interface in advance. Here is the backup code:
Form.h:
#ifndef Form_h#defineForm_h#include<QWidget>namespaceUi {classForm;}classForm: Publicqwidget{Q_object Public: ExplicitForm (Qwidget *parent =0); ~Form (); Signals:voidSendData (QString);PrivateSlots:voidon_sendbtn_clicked ();Private: Ui::form*UI;};#endif //Form_h
Form.cpp:
#include form.h " #include " ui_form.h form::form (Qwidget *parent): Qwidget (parent), UI ( new Ui::form) {Ui ->setupui (this );} Form:: ~form () { delete UI;} void form::on_sendbtn_clicked () {Emit SendData (UI ->linee->text ());}
MainWindow.h:
#ifndef Mainwindow_h#defineMainwindow_h#include<QMainWindow>#include"form.h"namespaceUi {classMainWindow;}classMainWindow: Publicqmainwindow{Q_object Public: ExplicitMainWindow (Qwidget *parent =0); ~MainWindow ();PrivateSlots:voidreceivedata (QString data);Private: Ui::mainwindow*UI;};#endif //Mainwindow_h
MainWindow.cpp:
#include"mainwindow.h"#include"ui_mainwindow.h"Mainwindow::mainwindow (Qwidget*parent): Qmainwindow (parent), UI (NewUi::mainwindow) {UI->SETUPUI ( This); //Pass Value TestForm *form=NewForm; Form->setgeometry ( -, -, -, -); Form-Show (); Connect (form,signal (SendData (QString)), This, SLOT (Receivedata (QString)));} MainWindow::~MainWindow () {DeleteUI;}voidmainwindow::receivedata (QString data) {UI->label->setText (data);}
Main.cpp:
" mainwindow.h " <QApplication>int main (intChar *argv[]) { qapplication a (argc, argv); MainWindow W; W.show (); return a.exec ();}
Transfer values between Qt forms (code backup)