alamminsalo / orion

Cross platform Twitch.tv client
GNU General Public License v3.0
314 stars 60 forks source link

Switch to function-pointer-style QObject::connect() #159

Closed rakslice closed 7 years ago

rakslice commented 7 years ago

Change QObject::connect() calls over to the function-pointer style introduced in Qt 5. https://doc.qt.io/qt-5/qobject.html#connect-3

In particular, this provides compile-time checking of parameter lists, avoiding situations where a function signature changes and a connect() call still builds but fails at runtime.

More backround: https://woboq.com/blog/new-signals-slots-syntax-in-qt5.html

rakslice commented 7 years ago

In the new format, in most cases this means you don't have to type the parameter list, although you do now have to type the class name for member functions:

E.g. SLOT(processError(QAbstractSocket::SocketError)) becomes &IrcChat::processError

In cases where a slot or signal you want to connect is ambiguous (e.g. because it refers to an overloaded function), you can statically cast it to a specific function pointer type to get the one you want. E.g.

SIGNAL(error(QAbstractSocket::SocketError)) becomes static_cast<void (QSslSocket::*)(QAbstractSocket::SocketError)>(&QSslSocket::error)

alamminsalo commented 7 years ago

Also one good way is to use lambda callbacks, I think we could streamline network code a good amount with them. I use them pretty often on new projects and have yet to have issues