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

    @public:
    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 http://qt-project.org/doc/qt-5.1/qtnetwork/qabstractsocket.html#error-2



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

    I found "this":http://qt-project.org/wiki/New_Signal_Slot_Syntax , useful for me.



  • I found the answer in this post
    http://qt-project.org/forums/viewthread/24855

    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
    QAbstractSocket:
    public:
    SocketError error() const;
    Q_SIGNALS:
    void error(QAbstractSocket::SocketError);
    so,
    connect(m_socket, static_cast<void (QTcpSocket::*) (QAbstractSocket::SocketError)>(&QAbstractSocket::error), this, &Bot::socketError);



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.