Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QNetworkReply implementation
Forum Update on Monday, May 27th 2025

[SOLVED] QNetworkReply implementation

Scheduled Pinned Locked Moved General and Desktop
12 Posts 2 Posters 4.0k 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.
  • I Offline
    I Offline
    Ilia1213
    wrote on last edited by
    #1

    Hi everybody!

    I'm using a "wkhtmltopdf":http://wkhtmltopdf.org to convert html page on the server. This library uses QNetworkAccessManager to communicate with network, but I need to forward all requests to the server through pipe.
    I found out Qt class QLocalSocket and now I'm getting all requests.
    So I wonder how to create QNetworkReply from this plain text requests and make it work properly with QNetowrkAccessManager.

    I'll be thankful for answers.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Max13
      wrote on last edited by
      #2

      Hi,

      If I understand and summarize, you receive (or want to receive) data from one side (via a socket like QLocalSocket) and you want to transmit from another side (for instance, as a QNetworkReply).

      If it's correct, your app acts as a server using a socket to receive data, and you have a QNetworkAccessManager, which you want to use to transmit data. You need to be more specific on how QNetworkAccessManager is used, because according to the doc:

      bq. The QNetworkAccessManager class allows the application to send network requests and receive replies

      So... I don't get the schema apparently. Can you be more specific on the architecture? Which software is where and how the requests are sent ?

      We all have started by asking questions. Then after some time, we can begin answering them.

      1 Reply Last reply
      0
      • I Offline
        I Offline
        Ilia1213
        wrote on last edited by
        #3

        Hi Max13,
        And thank you for your reply.

        Here is a client (some internet browser) that want to receive .pdf representation of some html page, so ti sends request to the server for example someserver.com/getPdf?url=someserver.com/index.html.

        On the server side I have nodejs server that communicate with server application(that have access to database and other stuff) via named pipe.

        When nodejs receives request to convert page (someserver.com/getPdf?url=someserver.com/index.html) it runs another program that should do this work converter (htmltopdfconverter.exe).

        Converter need to get some data from server side application.
        In QNetworkReply * QNetworkAccessManager::createRequest(Operation op, const QNetworkRequest & req, QIODevice * outgoingData = 0)
        I send HTTP request to server application trough named pipe and get response in raw format for example
        HTTP/1.1 200 OK
        Date: Fri, 19 Sep 2014 16:26:37 GMT
        Content-Type: image/png
        Content-Length: 1384
        ... some data is here ...

        So I need to create QNetworkReply for QNetworkAccessManager from this response.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Max13
          wrote on last edited by
          #4

          Sorry, english isn't my native language, that's maybe why I still don't get some points.

          So you have a user, who calls a nodeJs app (via HTTP), which SHOULD send a raw HTTP reply (the raw format response you mention) to htmltopdfconverter.exe which sends back a PDF to NodeJS, which sends it to the user, right? Should you make the call to get the desired HTML page, or will htmltopdfconverter.exe do it?

          We all have started by asking questions. Then after some time, we can begin answering them.

          1 Reply Last reply
          0
          • I Offline
            I Offline
            Ilia1213
            wrote on last edited by
            #5

            Yes, you are right.
            And here is third part - server application (name it serverapp.exe) from which I get raw HTTP response.
            Most work is already done. And the only thing I need to figure out is how to make QNetworkReply from raw HTTP.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              Max13
              wrote on last edited by
              #6

              Ok right. Why do you need a QNetworkReply again? Which app will send it to which app and how?

              We all have started by asking questions. Then after some time, we can begin answering them.

              1 Reply Last reply
              0
              • I Offline
                I Offline
                Ilia1213
                wrote on last edited by
                #7

                There is createRequest method in QNetworkAccessClass that should be fired each time user of this class call get, post and other methods.
                This method should take QNetworkRequest as one of arguments and return QNetworkReply (you can see it in documentation).

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  Max13
                  wrote on last edited by
                  #8

                  Do you mean that it's serverapp.exe which make the HTTP request to get raw response with HTML ?

                  We all have started by asking questions. Then after some time, we can begin answering them.

                  1 Reply Last reply
                  0
                  • I Offline
                    I Offline
                    Ilia1213
                    wrote on last edited by
                    #9

                    I solved my problem.
                    I found "article":http://doc.qt.digia.com/qq/32/qq32-webkit-protocols.html that perfectly describes my situation.
                    For some reason emit doesn't work from subclass:
                    @emit readyRead();
                    emit finished();
                    @

                    So you should change with:

                    @
                    QTimer::singleShot( 0, this, SIGNAL(readyRead()) );
                    QTimer::singleShot( 0, this, SIGNAL(finished()) );
                    @

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      Max13
                      wrote on last edited by
                      #10

                      Fine !
                      Sorry for not understanding quickly, but I still don't get why you had to reimplement createReply?

                      Because it's NodeJS which replies to the client, and when querying with Qt, you get the full response without subclassing :S

                      We all have started by asking questions. Then after some time, we can begin answering them.

                      1 Reply Last reply
                      0
                      • I Offline
                        I Offline
                        Ilia1213
                        wrote on last edited by
                        #11

                        Structure of server is more complex. It's not just nodejs. Here is a server application which processes all requests and sending responses. To connect with the server application you should use named pipe, but QNAM doesn't support QLocalSocket. Though the only way to process request through the server application is to intercept requests that passing through the QNAM forward them to the server application via QLocalSocket, get response and create QNetworkReply for QNAM.
                        I hope this clarify some of your questions.

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          Max13
                          wrote on last edited by
                          #12

                          Ok thx.

                          Now I get it.

                          We all have started by asking questions. Then after some time, we can begin answering them.

                          1 Reply Last reply
                          0

                          • Login

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