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. Integrate QT client in Socket.io demo
Forum Update on Monday, May 27th 2025

Integrate QT client in Socket.io demo

Scheduled Pinned Locked Moved General and Desktop
node.jssocket.ioweb clientnetwork
10 Posts 2 Posters 9.4k 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.
  • A Offline
    A Offline
    Athair
    wrote on last edited by Athair
    #1

    Hello everyone!
    I am a beginner and would like to understand how to realize this small application, using node.js, socket.io and QT.

    I made a server-side chat, following the tutorial on socket.io: I created a server using node.js and going to http://localhost:3000 I can access the webclient.
    Now I would like to create a desktop client (QT and C ++) that exploits the same server nodejs. How can I get this? [sketch]

    I found QtSocketIo (a conversion of socket.io for QT) but do not get how to use it in my project. Launching the example, in echoserver.h I get this error: "Project ERROR: Unknown module(s) in QT: socketio".

    // echoserver.h in QtSocketIo https://github.com/KurtPattyn/QtSocketIo.git
    
    #ifndef ECHOCLIENT_H
    #define ECHOCLIENT_H 
    
    #include <QtCore/QObject>
    #include <QtSocketIo/QSocketIoClient> // NOT FOUND
    
    class EchoClient : public QObject
    {
        Q_OBJECT
    public:
        explicit EchoClient(QObject *parent = Q_NULLPTR);
        virtual ~EchoClient();
    
        void open(QUrl url);
    
    public Q_SLOTS:
        void messageReceived(QString message);
        void errorReceived(QString reason, QString advice);
        void ackReceived(int messageId, QJsonArray arguments);
        void connected(QString endpoint);
        void disconnected(QString endpoint);
        void heartbeatReceived();
    
    private:
        QSocketIoClient m_client;
    };
    
    #endif // ECHOCLIENT_H
    

    I am sorry for my bad English. Thank you all! :)

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Did you first build and install that library ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi and welcome to devnet,

        Did you first build and install that library ?

        A Offline
        A Offline
        Athair
        wrote on last edited by
        #3

        @SGaist Thanks for your reply!
        I tried to import the QtSocketIo/src /socketio/socketio.pro but .cpp and .h files are not loaded. I'm have this error:
        error: Missing CMake tests

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You should also get the code from the pull request

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply
          0
          • SGaistS SGaist

            You should also get the code from the pull request

            A Offline
            A Offline
            Athair
            wrote on last edited by Athair
            #5

            @SGaist Sorry if I reply now. What do you mean?
            If you want to give me an advice or suggestions. They are welcome.
            My focus is to have a client-server model with a client in QT and a WebClient.

            Thanks again for your time!

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Sorry, I meant that you would need that pull request to build the QtSocketIo module

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              A 1 Reply Last reply
              0
              • SGaistS SGaist

                Sorry, I meant that you would need that pull request to build the QtSocketIo module

                A Offline
                A Offline
                Athair
                wrote on last edited by Athair
                #7

                @SGaist Thank You! Other people have had the same problem, without any replies.
                I have found a workaround: I used normal WebSockets (not socket.io).
                wp for node.js: https://www.npmjs.com/package/ws
                QWebSockets for Qt: http://doc.qt.io/qt-5/qwebsocket.html

                Example:

                // mainwindow.cpp (QtClient)
                void MainWindow::onConnected()
                {
                    connect(&m_webSocket, &QWebSocket::textMessageReceived, this, &MainWindow::onTextMessageReceived);
                    m_webSocket.sendTextMessage(QStringLiteral("Hello World! - from QtClient"));
                }
                
                // index.html (WebClient)
                socket.onopen = function() {
                    socket.send("Hello World! - from WebClient"); 
                };
                // server.js
                socket.on('connection', function(ws) {
                  ws.on('message', function(message) {
                    var m = JSON.parse(message);
                    console.log(m);
                  });
                });
                
                // console node
                C:\Users\PietroP\Desktop\cs\v0.3>node server.js
                Server connect on http://192.168.1.60:3000/
                a user connected
                Hello World! - from WebClient
                a user connected
                Hello World! - from QtClient
                

                Thanks for all!

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  You're welcome !

                  Since you have it working now, please use the Topic Tool button to mark the thread as solved so other forum users may know a solution has been found :)

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  A 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    You're welcome !

                    Since you have it working now, please use the Topic Tool button to mark the thread as solved so other forum users may know a solution has been found :)

                    A Offline
                    A Offline
                    Athair
                    wrote on last edited by
                    #9

                    @SGaist Hello! In TopicTool I only see the "delete" button!

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Then just edit the title by hand and prepend [solved]

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      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