Signal transfer between Qt windows

Source: Internet
Author: User

Application Scenarios:
A child window is created under the main window as a member, and when clicked on a button in the Subwindow, the main window receives its signal and handles it.

Example:
child window class:

#ifndef Update_view_h#define update_view_h#include "ui_update_subwindows.h"#include <QtGui/QMainWindow>Class Updateview: Publicqmainwindow{Q_objectPrivate: Ui_update::update_mainwindow Ui; Public:Updateview(qwidget* parent =0, Qt::wflags flags =0); ~updateview (); Signals:voidUp_select_update_file (Qpushbutton *);PrivateSlotsvoid Emit_select_button();};#endif //
#include "UpdateView.h"UpdateView::UpdateView(QWidget* parent,Qt::WFlags flags) : QMainWindow(parent,flags){    ui.setupUi(this);    connect(ui.pushButton,SIGNAL(clicked()),this,SLOT(emit_select_button())):: ~UpdateView(){}void UpdateView::emit_select_button(){    emit up_select_update_file(ui.pushButton);}

Main Window signal Slot

void export_da::update_da(){    update_view = new UpdateView(this);    connect(update_view,SIGNAL(up_select_update_file(QPushButton*)),this,SLOT(select_update_file(QPushButton*)));    update_view->show();}

Here's update_view even though my subwindow, and the signal function that it sends Up_select_update_file is the qpushbutton* type, the realization is that I want to pass the button of the child window to the main window, and use the contents of the main window to set this button.

void export_da::select_update_file(QPushButton* update_file){    = QFileDialog::getOpenFileName(this,tr("Save File"),".",tr("TEXT files (.txt)"));    update_file->setText(update_file_name);}

Signal transfer between Qt windows

Related Article

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.