Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[SOLVED] QNetworkReply implementation
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.
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 ?
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
... some data is here ...
So I need to create QNetworkReply for QNetworkAccessManager from this response.
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?
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.
Ok right. Why do you need a QNetworkReply again? Which app will send it to which app and how?
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).
Do you mean that it's serverapp.exe which make the HTTP request to get raw response with HTML ?
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:
So you should change with:
QTimer::singleShot( 0, this, SIGNAL(readyRead()) );
QTimer::singleShot( 0, this, SIGNAL(finished()) );
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
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.
Now I get it.