Important: Please read the Qt Code of Conduct -

Error with signal

  • Hello,

    i want to use the new Qt 5 syntax for Signals & Slots.
    but is compliacted i think.
    Can you help me ?
    This is my problem

    In my class Bot i have a QTcpSocket named m_socket, and i do a connect

    @connect(m_socket, &QTcpSocket::error, this, &Bot::socketError);@

    there is my socketError slot

    @void Bot::socketError(QAbstractSocket::SocketError e)


    and there is my .h

    void socketError(QAbstractSocket::SocketError e);@

    and there my error

    bq. bot\Bot.cpp:14: error: no matching function for call to 'Bot::connect(QTcpSocket*&, <unresolved overloaded function type>, Bot* const, void (Bot::*)(QAbstractSocket::SocketError))'
    connect(m_socket, &QTcpSocket::error, this, &Bot::socketError);

    Can you help me with that ?

    i just want to use this signal

  • Yes, looks complicated syntax compared to old, string based.

    I found "this": , useful for me.

  • I found the answer in this post

    But I do not understand the connect line

    @connect(m_socket, static_cast<void (QTcpSocket::*) (QAbstractSocket::SocketError)>(&QAbstractSocket::error), this, &Bot::socketError);@

  • overloaded function type
    QTcpSocket : public QAbstractSocket
    SocketError error() const;
    void error(QAbstractSocket::SocketError);
    connect(m_socket, static_cast<void (QTcpSocket::*) (QAbstractSocket::SocketError)>(&QAbstractSocket::error), this, &Bot::socketError);

  • hi ,
    You can simply use this as well ...
    (in .h)
    void error(QTcpSocket::SocketError SocketError);
    (in .cpp)
    emit error(pSocket->error());//Where you want to emit...

Log in to reply