What is the point of having & operator at the beginning of QObject:: destroyed and Ship:: onCannonBallDestroyed
connect( canonball, &QObject::destroyed, this, &Ship::onCannonballDestroyed );
connect( canonball, &QObject::destroyed, this, &Ship::onCannonballDestroyed );
To copy to clipboard, switch view to plain text mode
This is the new, type-safe form of QObject::connect(), which uses the "pointer to member function" style of giving the signal and slot pair. "&QObject:: destroyed" is the address of (pointer to) the "destroyed" signal (a member function) of the QObject class.
It is better to use this new style instead of the old one:
connect( cannonball,
SIGNAL( destroyed
( QObject * ),
this,
SLOT( onCannonballDestroyed
( QObject * ) ) );
connect( cannonball, SIGNAL( destroyed( QObject * ), this, SLOT( onCannonballDestroyed( QObject * ) ) );
To copy to clipboard, switch view to plain text mode
because the new style will not compile if you give the wrong arguments. The old style will compile, but will fail at run time if you give it the wrong arguments. That isn't so good, because unless you read the messages coming from the runtime output in the debugger, you will not know that the connect() failed and will wonder why your app isn't handling the signals in the way you think it should be.
Bookmarks