Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. Qt GRPC: Why is handling a response required for a grpc call?

Qt GRPC: Why is handling a response required for a grpc call?

Scheduled Pinned Locked Moved Unsolved Qt 6
5 Posts 4 Posters 271 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    spyropoulosamandad
    wrote on 31 Jan 2025, 18:30 last edited by
    #1

    I've recently been working with Qt Grpc in 6.8.1 in C++, following along the Client Guide Example:

    std::unique_ptr<QGrpcCallReply> reply = m_client.UnaryCall(requestMessage);
    const auto *replyPtr = reply.get(); // 1
    QObject::connect(
        replyPtr, &QGrpcCallReply::finished, replyPtr,
        [reply = std::move(reply)](const QGrpcStatus &status) {
            ...
        },
        Qt::SingleShotConnection        // 2
    );
    

    I was able to get the example to work. However, I noticed that if I omitted the code which handles the response, my server would not receive any call. Specifically, just

    std::unique_ptr<QGrpcCallReply> reply = m_client.UnaryCall(requestMessage);
    

    would not execute a grpc call that my server received. Why? In the full example above, does the call get executed when QObject::connect is called?

    I understand that the vast majority of the time, we need to check the response to gain information so this is an edge case. I am curious why the code didn't behave as I expected.

    C 1 Reply Last reply 31 Jan 2025, 18:57
    0
    • S spyropoulosamandad
      31 Jan 2025, 18:30

      I've recently been working with Qt Grpc in 6.8.1 in C++, following along the Client Guide Example:

      std::unique_ptr<QGrpcCallReply> reply = m_client.UnaryCall(requestMessage);
      const auto *replyPtr = reply.get(); // 1
      QObject::connect(
          replyPtr, &QGrpcCallReply::finished, replyPtr,
          [reply = std::move(reply)](const QGrpcStatus &status) {
              ...
          },
          Qt::SingleShotConnection        // 2
      );
      

      I was able to get the example to work. However, I noticed that if I omitted the code which handles the response, my server would not receive any call. Specifically, just

      std::unique_ptr<QGrpcCallReply> reply = m_client.UnaryCall(requestMessage);
      

      would not execute a grpc call that my server received. Why? In the full example above, does the call get executed when QObject::connect is called?

      I understand that the vast majority of the time, we need to check the response to gain information so this is an edge case. I am curious why the code didn't behave as I expected.

      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 31 Jan 2025, 18:57 last edited by
      #2

      std::unique_ptr<QGrpcCallReply> reply = m_client.UnaryCall(requestMessage);

      I would guess you should think about how long this object is alive.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • S Offline
        S Offline
        semlanik
        wrote on 26 Feb 2025, 16:23 last edited by
        #3

        You indeed answered to your own question. If nothing supposed to receive the response, request is ignored in case is there is no active channel established to the server. And this can happen if the call happens in the same stack with QGrpcHttp2Channel ctor.

        I think we may make this behavior controllable, so add the call option that allows always "no-discard" calls.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          semlanik
          wrote on 26 Feb 2025, 16:32 last edited by
          #4

          ...or vice-versa opt out the current behavior and send everything no matter someone still wait for the response or not.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            ddob
            wrote on 26 Feb 2025, 19:01 last edited by
            #5

            Hey, as our docs state: "Users are responsible for managing the unique RPC handlers returned by the Client interface", the RPC object has to be alive to continue any processing. You don't need to connect to finish but it's highly recommended since you don't know when the time for deletion would be.

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved