[SOLVED]I need explanation about connect()



  • Signal and slot mechanism is heart of qt.So i want to learn it thoroughly.There are somethings that preoccupies me. QObject::Connect() has five different form.One of them takes 3 arguments.Qt documentation(5.1.0) says about it that
    @
    QMetaObject::Connection QObject::connect(const QObject * sender, const char * signal, const char * method, Qt::ConnectionType type = Qt::AutoConnection) const
    This function overloads connect().

    Connects signal from the sender object to this object's method.

    Equivalent to connect(sender, signal, this, method, type).

    Every connection you make emits a signal, so duplicate connections emit two signals. You can break a connection using disconnect().

    Note: This function is thread-safe.

    See also disconnect().
    @
    About "Equivalent to connect(sender, signal, this, method, type)." above:
    1-Does class which pointing by *this have to be a subclass of QObject?
    2-Does method had to be declared as custom slot?(in case of it is not member any QObject subclass)
    3-Do I have to use SLOT macro such SLOT ( method ( args ) ) ?
    4-Do I have to use Q_OBJECT macro in header?

    All questions above about qt5. Thanks.


  • Lifetime Qt Champion

    Hi

    1. No, you can declare slots as public, protected or private.
    2. Using this form of connect, yes
    3. Yes you have to

    You can read more about it in this "chapter":http://qt-project.org/doc/qt-5.0/qtcore/signalsandslots.html



  • Thank you again.Answers are
    1-Yes
    2-Yes
    3-Yes
    4-Yes


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.