Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It could be done using several methods , the easiest one (not the most clever) is making intermediate connection, from object A to mainwindows,mainwindow to B</p> <p>mainwindow.h</p> <pre><code>#ifndef MAINWINDOW_H #define MAINWINDOW_H #include &lt;QMainWindow&gt; #include "classa.h" #include "classb.h" namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); private: Ui::MainWindow *ui; classA *a; classB *b; signals: void TosignalA(); void TosignalB(); public slots: void emitB(); private slots: void on_pushButton_clicked(); }; #endif // MAINWINDOW_H </code></pre> <p>mainwindow.cpp</p> <pre><code>#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui-&gt;setupUi(this); a = new classA(this); b=new classB(this); connect(this,SIGNAL(TosignalA()),this-&gt;a,SLOT(emitsig())); connect(this-&gt;a,SIGNAL(signal()),this,SLOT(emitB())); connect(this,SIGNAL(TosignalB()),this-&gt;b,SLOT(on_signal())); } MainWindow::~MainWindow() { delete ui; } void MainWindow::emitB() { emit TosignalB(); } void MainWindow::on_pushButton_clicked() { emit TosignalA(); } </code></pre> <p>classa.h</p> <pre><code>#ifndef CLASSA_H #define CLASSA_H #include &lt;QObject&gt; class classA : public QObject { Q_OBJECT public: explicit classA(QObject *parent = 0); signals: void signal(); public slots: void emitsig(); }; #endif // CLASSA_H </code></pre> <p>classa.cpp</p> <pre><code>#include "classa.h" classA::classA(QObject *parent) : QObject(parent) { } void classA::emitsig() { emit signal(); } </code></pre> <p>classb.h</p> <pre><code>#ifndef CLASSB_H #define CLASSB_H #include &lt;QObject&gt; #include &lt;QtGui&gt; class classB : public QObject { Q_OBJECT public: explicit classB(QObject *parent = 0); signals: public slots: void on_signal(); }; #endif // CLASSB_H </code></pre> <p>classb.cpp</p> <pre><code>#include "classb.h" classB::classB(QObject *parent) : QObject(parent) { } void classB::on_signal() { QMessageBox *msgBox = new QMessageBox(); msgBox-&gt;setText("signal emitted!"); msgBox-&gt;exec(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload