1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| #include "mainwindow.h" #include "ui_mainwindow.h" #include <QDebug>
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this);
connect(ui->closeBtn, &QPushButton::clicked, this, &MainWindow::close);
m_myself = new MySelf(this); m_myfriend = new MyFriend(this);
void (MyFriend::*friend1)() = &MyFriend::wantToTalk; void (MyFriend::*friend2)(QString) = &MyFriend::wantToTalk;
void (MySelf::*myself1)(QString) = &MySelf::doTalking; void (MySelf::*myself2)() = &MySelf::doTalking;
connect(m_myfriend, friend2, this, &MainWindow::talkingByMainWindow);
connect(m_myfriend, friend2, m_myself, myself1); connect(m_myfriend, friend1, m_myself, myself2);
connect(ui->talkingBtn, &QPushButton::clicked, this, &MainWindow::talkingSlot); }
MainWindow::~MainWindow() { delete ui; }
void MainWindow::talkingSlot() { emit m_myfriend->wantToTalk(); emit m_myfriend->wantToTalk("hello"); }
void MainWindow::talkingByMainWindow() { qDebug() << "eat something......"; }
|