Important: Please read the Qt Code of Conduct -

Client-Server communication through QWebChannel. Create new QT application processes whenever a new client is connected.

  • I have created an opengl based application having HTML UI and c++ logic, connected through QWebChannel.

    For desktop versions(windows/linux), I created QWebEngineView to display the HTML UI. I was able to create-launch-exchange data between html and c++ application successfully.

    Now, I want to create a browser based app using the same HTML UI and C++ logic. I can achieve this using QWebSocketServer, qTcpSocket, QWebChannelAbstractTransport classes and avoid creating webengineview if it is a webapp.

    I want to load my Qt application in a new process whenever a client is connected.

    JsToCppProxy webRelayMsgObj;

    QWebChannel webChannel;
    webChannel.registerObject("JsToCppProxy", &webRelayMsgObj);

    WebSocketTransport pSocketTransport = new WebSocketTransport(m_server->nextPendingConnection());*

    QObject::connect(this, (void(WebSocketServer::)(QWebChannelAbstractTransport))&WebSocketServer::clientConnected,
    &m_WebChannel, &QWebChannel::connectTo);

    emit clientConnected(pSocketTransport);

    WebSocketTransport is derived from QWebChannelAbstractTransport. I picked it up from one of the qt examples.


    1. I'm new to socket programming. Above piece of code i have to do in a new Qt process. But m_server instance is in another Qt process. Can I create WebSocketTransport in one process and access the same instance in another Qt process to create QWebChannel(to connect slot)?
    2. QServer resides in one process(which has a qapplication) and my application also has a qapplication.
      Is it fine to create different qapplications in different processes?
      Is there any sample application for this scenario?
      Is the direction I'm proceeding correct? Kindly help, I'm stuck.

Log in to reply