Transfer values between Qt forms (code backup)

Source: Internet
Author: User

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-&GT;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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.