Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A simple example could be something like this. Say you have a class like ProgramStarter:</p> <pre><code>#include &lt;QObject&gt; class ProgramStarter : public QObject { Q_OBJECT public slots: void startProgram() { //Do stuff } }; </code></pre> <p>and something like this where ProgramStarter is used:</p> <pre><code>#include &lt;QtGui/QApplication&gt; #include &lt;QPushButton&gt; #include &lt;QObject&gt; #include "programstarter.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); QPushButton *testButton = new QPushButton("Push me"); testButton-&gt;resize(100, 40); testButton-&gt;show(); ProgramStarter *program = new ProgramStarter; QObject::connect(testButton, SIGNAL(clicked()), program, SLOT(startProgram())); return app.exec(); } </code></pre> <p>Qt uses signals and slots to communicate between objects. The core idea is that signals are emitted when events occur and these signals can be connected to slots. In this case the button emits a clicked() signal when the button is pressed and the clicked() signal is connected to the startProgram() slot. So when the button is pressed, startProgram() is called.</p> <p>Qt has a meta-object system for enabling the use of signals and slots, among other things. This is the reason why ProgramStarter inherits QObject and why the Q_OBJECT macro is in the header. I highly suggest reading this if you want to understand how signals and slots and the meta-object system work in Qt: <a href="http://doc.qt.io/qt-5/signalsandslots.html" rel="nofollow">http://doc.qt.io/qt-5/signalsandslots.html</a></p>
    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.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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