Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. Data via Qt Creator Console from WebSocket
Forum Update on Monday, May 27th 2025

Data via Qt Creator Console from WebSocket

Scheduled Pinned Locked Moved Unsolved Qt WebKit
7 Posts 3 Posters 1.1k 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.
  • S Offline
    S Offline
    Samuel123
    wrote on 6 Apr 2023, 15:28 last edited by
    #1

    Hello,
    I would like to know how to output information from a WebSocket via Qt Creator Console. This is my code, which is not working:

    #include <QCoreApplication>
    #include <QWebSocket>
    #include <QtDebug>

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    //WebSocket:
    QWebSocket *socket = new QWebSocket();
    socket->open(QUrl("ws://IP-Adresse"));
    
    QObject::connect(socket, &QWebSocket::connected, [] () {
    	qDebug() << "WebSocket connected";
    });
    
    QObject::connect(socket, &QWebSocket::connected, [] (const QString &message) {
    	qDebug() << Nachricht: " << message;
    });
    
    QObject::connect(socket, &QWebSocket::disconnected, [] () {
    	qDebug() << "WebSocket disconnected";
    });
    
    socket->close();
    return a.exec();
    

    }

    Does someone have solutions?

    ? 2 Replies Last reply 6 Apr 2023, 16:33
    0
    • S Samuel123
      6 Apr 2023, 15:28

      Hello,
      I would like to know how to output information from a WebSocket via Qt Creator Console. This is my code, which is not working:

      #include <QCoreApplication>
      #include <QWebSocket>
      #include <QtDebug>

      int main(int argc, char *argv[])
      {
      QCoreApplication a(argc, argv);

      //WebSocket:
      QWebSocket *socket = new QWebSocket();
      socket->open(QUrl("ws://IP-Adresse"));
      
      QObject::connect(socket, &QWebSocket::connected, [] () {
      	qDebug() << "WebSocket connected";
      });
      
      QObject::connect(socket, &QWebSocket::connected, [] (const QString &message) {
      	qDebug() << Nachricht: " << message;
      });
      
      QObject::connect(socket, &QWebSocket::disconnected, [] () {
      	qDebug() << "WebSocket disconnected";
      });
      
      socket->close();
      return a.exec();
      

      }

      Does someone have solutions?

      ? Offline
      ? Offline
      A Former User
      wrote on 6 Apr 2023, 16:33 last edited by A Former User 4 Jun 2023, 16:35
      #2

      @Samuel123 yes easy one : connect your lambda function to the appropriate signal : use textMessageReceived or binaryMessageReceived which are both intended to be emitted upon message reception on the contrary of connected which wont ever be triggered in that case.

      S 1 Reply Last reply 13 Apr 2023, 09:43
      0
      • ? A Former User
        6 Apr 2023, 16:33

        @Samuel123 yes easy one : connect your lambda function to the appropriate signal : use textMessageReceived or binaryMessageReceived which are both intended to be emitted upon message reception on the contrary of connected which wont ever be triggered in that case.

        S Offline
        S Offline
        Samuel123
        wrote on 13 Apr 2023, 09:43 last edited by
        #3

        @ankou29666 Thank you for your answer. Can you provide an example of how to integrate that into a code?

        1 Reply Last reply
        0
        • S Samuel123
          6 Apr 2023, 15:28

          Hello,
          I would like to know how to output information from a WebSocket via Qt Creator Console. This is my code, which is not working:

          #include <QCoreApplication>
          #include <QWebSocket>
          #include <QtDebug>

          int main(int argc, char *argv[])
          {
          QCoreApplication a(argc, argv);

          //WebSocket:
          QWebSocket *socket = new QWebSocket();
          socket->open(QUrl("ws://IP-Adresse"));
          
          QObject::connect(socket, &QWebSocket::connected, [] () {
          	qDebug() << "WebSocket connected";
          });
          
          QObject::connect(socket, &QWebSocket::connected, [] (const QString &message) {
          	qDebug() << Nachricht: " << message;
          });
          
          QObject::connect(socket, &QWebSocket::disconnected, [] () {
          	qDebug() << "WebSocket disconnected";
          });
          
          socket->close();
          return a.exec();
          

          }

          Does someone have solutions?

          ? Offline
          ? Offline
          A Former User
          wrote on 13 Apr 2023, 09:49 last edited by A Former User
          #4

          @Samuel123 said in Data via Qt Creator Console from WebSocket:

          QObject::connect(socket, &QWebSocket::connected, [] (const QString &message) {
          qDebug() << Nachricht: " << message;
          });

          becomes

          QObject::connect(socket, &QWebSocket::textMessageReceived, [] (const QString &message) {
          	qDebug() << Nachricht: " << message;
          });
          
          S 1 Reply Last reply 13 Apr 2023, 12:37
          0
          • ? A Former User
            13 Apr 2023, 09:49

            @Samuel123 said in Data via Qt Creator Console from WebSocket:

            QObject::connect(socket, &QWebSocket::connected, [] (const QString &message) {
            qDebug() << Nachricht: " << message;
            });

            becomes

            QObject::connect(socket, &QWebSocket::textMessageReceived, [] (const QString &message) {
            	qDebug() << Nachricht: " << message;
            });
            
            S Offline
            S Offline
            Samuel123
            wrote on 13 Apr 2023, 12:37 last edited by
            #5

            @ankou29666 I changed it, but it didn't make any difference. Do you know if it's enough to just enter the IP address of the WebSocket after "socket->open"?

            SGaistS 1 Reply Last reply 13 Apr 2023, 16:08
            0
            • S Samuel123
              13 Apr 2023, 12:37

              @ankou29666 I changed it, but it didn't make any difference. Do you know if it's enough to just enter the IP address of the WebSocket after "socket->open"?

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on 13 Apr 2023, 16:08 last edited by
              #6

              Hi,

              Why are you closing the socket before calling ˋapp.exec();` ?

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

              S 1 Reply Last reply 16 Apr 2023, 15:51
              1
              • SGaistS SGaist
                13 Apr 2023, 16:08

                Hi,

                Why are you closing the socket before calling ˋapp.exec();` ?

                S Offline
                S Offline
                Samuel123
                wrote on 16 Apr 2023, 15:51 last edited by
                #7

                @SGaist Now it worked. Thanks very much.

                1 Reply Last reply
                0

                1/7

                6 Apr 2023, 15:28

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved