QT 主窗口中调用子窗口控件和信号传递 | 您所在的位置:网站首页 › qt动态库加载窗口中槽函数不响应 › QT 主窗口中调用子窗口控件和信号传递 |
QT 主窗口中调用子窗口控件和信号传递
文件目录 Headers: mainwindow.h renderdialog.h Souces: main.cpp mainwindow.cpp rederdialog.cpp 实现: 由mainwindow菜单栏弹出dialog,该子窗口dialog中的buttonbox在按键ok/cancel后,mainwindow返回相应的值。 方法: dialog的按键动作通过emit发送SIGNAL作为主窗口槽的触发信号,主窗口接收到子窗口SIGNAL信号后,触发SLOT信号,判断QAbstractButton格式的内容(ok/cancel)作响应。 该方法的要求如下: 在mainwindow.h要声明子窗口的RenderDialog类renderdialog,并定义响应的槽函数btnbox(QAbstractButton *),因为传送的信号类型就是QAbstractButton,用来判断buttonbox的内容ok/cancel. mainwindow.h #include "renderdialog.h" #include "ui_renderdialog.h" private: Ui::MainWindow *ui; private: RenderDialog *renderdialog; private slots: // void hellook(); // void hellocancel(); void btnbox(QAbstractButton *);//SLOT信号mainwindow.cpp // connect(renderdialog,SIGNAL(buttonbox_ok()),this,SLOT(hellook())); // connect(renderdialog,SIGNAL(buttonbox_cancel()),this,SLOT(hellocancel())); connect(renderdialog,SIGNAL(buttonbox(QAbstractButton *)),this,SLOT(btnbox(QAbstractButton *))); /* void MainWindow::hellook() { qDebug() qDebug()buttonBox->button(QDialogButtonBox::Cancel)) { qDebug() |
CopyRight 2018-2019 实验室设备网 版权所有 |