Search code examples
c++linuxqtrestreal-time

QT REST development for HTML web client on linux


In the Linux system we need to stream data as JSON format for real time data communication. for example we are tuning volume through web client than it should post to server and vice versa. What could be best way to build rest development with QT which is communicating the other module too.


Solution

  • It has been added direct support of JSON in Qt 5. Check available classes here.

    To communicate with web part you should use QNetworkManagerAccess class.

    Here it's example of how it can be implemented (not tested):

    QVariantMap top;
    top.insert( "key1", QString( "value1" ) );
    top.insert( "key2", QString( "value2" ) );
    const QJsonDocument doc = QJsonDocument::fromVariant(top);
    QByteArray postData = doc.toJson();
    
    QNetworkAccessManager* manager = new QNetworkAccessManager(this);
    
    QNetworkRequest req;
    req.setUrl(QUrl("http://www.test.com"));
    req.setHeader(QNetworkRequest::ContentTypeHeader,"application/json");
    
    QNetworkReply *reply = manager->post(req,postData);
    ...