0

I saw an example for running a TCP Server with Qt.

In this example a class named Client was created, its constructor had 5 connections between signals and slots of QTcpSocket and Client class. In one of the connections this code was written:

connect(&socket,QOverload<QAbstractSocket::SocketError>::of(&QAbstractSocket::errorOccurred),this,&Client::error);

I am familiar with signal and slot mechanism and how to connect.

Now my questions are:

  • What is the role of of in above code?
  • According to QAbstractSocket's errorOccurred signal, why do we use QOverload?

Thanks a lot.

  • Where do you saw it exactly? I think it's a leftover from QAbstractSocket::error -> QAbstractSocket::errorOccured changes. There were two functions called error (one getter and the signal) but the signal was deprecated and renamed to errorOccured. So the QOverload is no longer needed. – chehrlic Apr 15 '23 at 12:05
  • 1
    `QOverload<...>::of` uses template metaprogramming tricks to select a particular overload (the one whose parameter types are in the angle brackets) from a set of overloaded member functions. Sometimes a signal or a slot is overloaded (there are multiple signals with the same name, taking different parameter types), and then just passing `&ClassName::signalNam` leads to compiler error, as the compiler can't tell which overload you meant to pass. `QOverload<...>::of` is a convenient syntax to disambiguate. – Igor Tandetnik Apr 15 '23 at 16:39

0 Answers0