Unable to connect QJsonRpcSocket::messageReceived with a lambda

Issue #8 invalid
Kirill Bukaev created an issue

Hello

QObject::connect(m_socket, &QJsonRpcSocket::messageReceived, [this] (const QJsonRpcMessage &message) {

    });

This code produces the following error:

error LNK2001: unresolved external symbol "public: static struct QMetaObject const QJsonRpcSocket::staticMetaObject" (?staticMetaObject@QJsonRpcSocket@@2UQMetaObject@@B)

P.S. Qt 5.2 beta, Compiler - MSVC 2010

Comments (6)

  1. Matt Broadstone

    I haven't tested with 5.2 yet, but this looks like you're not properly linking to qjsonrpc. If it can't find the staticMetaObject for the socket, that means you can't use the socket at all (not specific to lambdas). Can you confirm that other "normal" cases work? Or confirm that you are able to compile and run the examples, for instance.

  2. Kirill Bukaev reporter

    Yep, everything is working except that connection. The old way is working too:

    QObject::connect(m_socket, SIGNAL(messageReceived(QJsonRpcMessage)), q, SLOT(mySlot()));
    

    I tried it with Mingw 4.8 and it is working good with the new connection style. It is strange, because lambdas work with everything except QJsonRPC using MSVC 2010.

  3. Kirill Bukaev reporter

    It works when I replace

    #ifdef QJSONRPC_SHARED
    #   ifdef QJSONRPC_BUILD
    #       define QJSONRPC_EXPORT Q_DECL_EXPORT
    #   else
    #       define QJSONRPC_EXPORT Q_DECL_IMPORT
    #   endif
    #else
    #   define QJSONRPC_EXPORT
    #endif
    

    with

    #   ifdef QJSONRPC_BUILD
    #       define QJSONRPC_EXPORT Q_DECL_EXPORT
    #   else
    #       define QJSONRPC_EXPORT Q_DECL_IMPORT
    #   endif
    
  4. Matt Broadstone

    sorry, I've been incredibly busy!

    This is interesting.. first of all doesn't that just mean you should define "QJSONRPC_SHARED" in your build instead (instead of deleting that code)? Also, this would seem to indicate that you are not including qjsonrpc.pri in your project, this is where it includes that define by default.

    Can you confirm?

    Also: this is more than likely a problem with documentation, or the complete lack of it :)

  5. Kirill Bukaev reporter

    first of all doesn't that just mean you should define "QJSONRPC_SHARED" in your build instead (instead of deleting that code)?

    I tried but it didn't work(maybe I forgot to do a full clean)

    that you are not including qjsonrpc.pri in your project

    You are right. I included it, did a full clean and then rebuilt - working fine now!

    Thanks, Matt!

  6. Log in to comment