Qt 視窗間的訊號傳遞

來源:互聯網
上載者:User

標籤:qt4   多視窗   訊號槽   應用   

應用情境:
主視窗下建立了一個子視窗為其成員,當點擊子視窗內的按鈕時,主視窗接收其訊號並做處理

樣本:
子視窗類:

#ifndef UPDATE_VIEW_H#define UPDATE_VIEW_H#include "ui_update_subwindows.h"#include <QtGui/QMainWindow>class UpdateView : public QMainWindow{    Q_OBJECTprivate:    Ui_update::Update_MainWindow ui;public:    UpdateView(QWidget* parent = 0,Qt::WFlags flags = 0);    ~UpdateView();signals:    void up_select_update_file(QPushButton *);private slots:    void 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 :: ~UpdateView(){}void UpdateView::emit_select_button(){    emit up_select_update_file(ui.pushButton);}

主視窗訊號槽

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();}

這裡的update_view 即使我的子視窗,而其發送的訊號函數up_select_update_file裡的參數是QPushButton* 類型,實現的是,我想將子視窗的按鈕傳遞給主視窗,採用主視窗的內容去set這個按鈕。

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

Qt 視窗間的訊號傳遞

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.