views:

128

answers:

2
+5  Q: 

Qt HTTP Server?

I'd like to write a small HTTP server application that receives HTTP GET requests, processes them and sends out a reply. Because of the history of the application I'd favor using Qt for this, but all I can find is the other (more common) direction: Send a request to a server and receive a reply using QNetworkAccessManager. What I need is something like a socket that, when a request comes in, produces an object where I can pick url etc. of this request, so I can send out an appropriate reply.

Am I just blind or is nothing like this in the Qt framework? If so, can you recommend alternatives?

A: 

Try to avoid using Qt in critical code. Qt is good for GUI but not for utilities even if it has APIs for that.

Take a look at boost::asio ( http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/examples.html )

buratinas
"Qt is good for GUI but not for utilities even if it has APIs for that."I'd like to see some documentation/reasoning of that claim.
Morten Fjeldstad
because all objects inherit from QObject which adds unnecessary overhead auch as introspection capabilities. Introspection and etc. can be justified for GUI portion but not for libraries. Not to mention code dependency on moc.
buratinas
+2  A: 

A quick google search turned up http://doc.qt.nokia.com/solutions/4/qtservice/qtservice-example-server.html, which might be the thing you're looking for, i.e. a fully functional example processing HTTP GET requests using QTcpServer.

Greg S
Don't know how I could miss that. I thought there was some kind of abstraction and one does not need to use a "raw" QTcpServer. However, now I regex the GET line to extract the url. This url is passed to QUrl and from this point I have all the functionality I need. Thanks!
gre