The simplest solution is:
bool ok = QObject::connect(sender, SIGNAL(mySignal()), receiver, SLOT(mySlot());
Q_ASSERT_X(ok, Q_FUNC_INFO, "connect mySignal to mySlot");
Do not fall to the temptation of "shortening it". The variant below is a bug and becomes a no-op in release mode:
Q_ASSERT_X(QObject::connect(sender, SIGNAL(mySignal()),
receiver, SLOT(mySlot()),
Q_FUNC_INFO, "connect mySignal to mySlot");
This form would be entirely removed in release mode when not having the corresponding debug macro defined.
If you wish to throw, then you could start here:
try {
if (!QObject::connect(sender, SIGNAL(mySignal()), receiver, SLOT(mySlot()))
throw ...;
} catch ( .. )
qDebug() << "Could not connect ...";
qApp->exit(1);
}
You really should consider the new signal/slot syntax with Qt 5 and C++11 support which generates a compile-time warning.
That would result in something like:
connect(sender, &Sender::mySignal, mySlot);
You could even use a lambda to keep it short and easier to comprehend due to locality of related code:
connect(sender, &Sender::valueChanged, [=](const QString &newValue) {
receiver->updateValue("senderValue", newValue);
} );