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. How to send json-file to the address?
Forum Updated to NodeBB v4.3 + New Features

How to send json-file to the address?

Scheduled Pinned Locked Moved Solved General and Desktop
21 Posts 4 Posters 2.7k 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.
  • Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #5

    @Mikeeeeee said in How to send json-file to the address?:

    What do I need to fix?

    Read the documentation and examples and see that all socket functions are async in Qt.

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    1 Reply Last reply
    2
    • M Offline
      M Offline
      Mikeeeeee
      wrote on last edited by Mikeeeeee
      #6

      I tried to use the class from the example "SSL Echo Client Example", but it also does not work. Please tell me how to connect to the websocket?
      cpp

      SslEchoClient client(QUrl(QStringLiteral("wss://ws.binaryws.com/websockets/v3?app_id=xlY2chJRk0XoSL5")));
      qDebug()<<client->m_webSocket.isValid()<<client->m_webSocket.state();
      

      debug return: false QAbstractSocket::UnconnectedState

      1 Reply Last reply
      0
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #7

        Again: how should it work when the socket has no time to do the actual connection? The operations are asynchronous !

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        3
        • M Offline
          M Offline
          Mikeeeeee
          wrote on last edited by Mikeeeeee
          #8

          Okay, can you please tell me how I can run it asynchronously?
          Or maybe the program can wait until a socket connection appears?

          jsulmJ 1 Reply Last reply
          0
          • M Mikeeeeee

            Okay, can you please tell me how I can run it asynchronously?
            Or maybe the program can wait until a socket connection appears?

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by jsulm
            #9

            @Mikeeeeee said in How to send json-file to the address?:

            Okay, can you please tell me how I can run it asynchronously?

            You already do. You need to connect a slot to https://doc.qt.io/qt-5/qwebsocket.html#connected signal and in that slot call

            qDebug()<<myWebSocket.isValid();
            

            "Or maybe the program can wait until a socket connection appears?" - why don't you simply use signals/slots?!

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            2
            • M Offline
              M Offline
              Mikeeeeee
              wrote on last edited by
              #10

              I took the example code, and it says so:

              SslEchoClient::SslEchoClient(const QUrl &url, QObject *parent) :
                  QObject(parent)
              {
                  connect(&m_webSocket, &QWebSocket::connected, this, &SslEchoClient::onConnected);
                  connect(&m_webSocket, QOverload<const QList<QSslError>&>::of(&QWebSocket::sslErrors),
                          this, &SslEchoClient::onSslErrors);
                  m_webSocket.open(QUrl(url));
              }
              

              There are signals and slots, I create an object of this class, but it does not connect. Why?

              jsulmJ J.HilkJ 2 Replies Last reply
              0
              • M Mikeeeeee

                I took the example code, and it says so:

                SslEchoClient::SslEchoClient(const QUrl &url, QObject *parent) :
                    QObject(parent)
                {
                    connect(&m_webSocket, &QWebSocket::connected, this, &SslEchoClient::onConnected);
                    connect(&m_webSocket, QOverload<const QList<QSslError>&>::of(&QWebSocket::sslErrors),
                            this, &SslEchoClient::onSslErrors);
                    m_webSocket.open(QUrl(url));
                }
                

                There are signals and slots, I create an object of this class, but it does not connect. Why?

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by jsulm
                #11

                @Mikeeeeee said in How to send json-file to the address?:

                but it does not connect. Why?

                You know, there is https://doc.qt.io/qt-5/qwebsocket.html#error-1 signal.
                Did you connect a slot to it to see whether you get an error?

                Also see https://doc.qt.io/qt-5/qwebsocket.html#errorString

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                2
                • M Mikeeeeee

                  I took the example code, and it says so:

                  SslEchoClient::SslEchoClient(const QUrl &url, QObject *parent) :
                      QObject(parent)
                  {
                      connect(&m_webSocket, &QWebSocket::connected, this, &SslEchoClient::onConnected);
                      connect(&m_webSocket, QOverload<const QList<QSslError>&>::of(&QWebSocket::sslErrors),
                              this, &SslEchoClient::onSslErrors);
                      m_webSocket.open(QUrl(url));
                  }
                  

                  There are signals and slots, I create an object of this class, but it does not connect. Why?

                  J.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #12

                  @Mikeeeeee said in How to send json-file to the address?:

                  QWebSocket::sslErrors

                  why the overload ? as far as I can see sslErrors has no alternatives to QList<QSslErrors>

                  https://doc.qt.io/qt-5/qwebsocket-members.html


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  1 Reply Last reply
                  2
                  • M Offline
                    M Offline
                    Mikeeeeee
                    wrote on last edited by
                    #13

                    Tried to start an example "SslEchoClient", but it irzhe does not connect and does not display error messages.
                    In my project I connected the status output to the button:

                    #include "mainwindow.h"
                    #include "ui_mainwindow.h"
                    
                    MainWindow::MainWindow(QWidget *parent) :
                        QMainWindow(parent),
                        ui(new Ui::MainWindow)
                    {
                        ui->setupUi(this);
                    
                        myUrl = "wss://ws.binaryws.com/websockets/v3?app_id=xlY2chJRk0XoSL5";
                        myWebSocket.open(QUrl(myUrl));
                        qDebug()<<myWebSocket.isValid()<<myWebSocket.state();
                    
                    }
                    
                    MainWindow::~MainWindow()
                    {
                        delete ui;
                    }
                    
                    void MainWindow::on_testButton_clicked()
                    {
                        qDebug()<<myWebSocket.isValid()<<myWebSocket.state()<<myWebSocket.error();
                    }
                    

                    Debug return:
                    false QAbstractSocket::UnconnectedState QAbstractSocket::UnknownSocketError
                    false QAbstractSocket::UnconnectedState QAbstractSocket::UnknownSocketError
                    false QAbstractSocket::UnconnectedState QAbstractSocket::UnknownSocketError
                    false QAbstractSocket::UnconnectedState QAbstractSocket::UnknownSocketError

                    Why can't I even use the example "SslEchoClient" to connect to the websocket?

                    jsulmJ 1 Reply Last reply
                    0
                    • M Mikeeeeee

                      Tried to start an example "SslEchoClient", but it irzhe does not connect and does not display error messages.
                      In my project I connected the status output to the button:

                      #include "mainwindow.h"
                      #include "ui_mainwindow.h"
                      
                      MainWindow::MainWindow(QWidget *parent) :
                          QMainWindow(parent),
                          ui(new Ui::MainWindow)
                      {
                          ui->setupUi(this);
                      
                          myUrl = "wss://ws.binaryws.com/websockets/v3?app_id=xlY2chJRk0XoSL5";
                          myWebSocket.open(QUrl(myUrl));
                          qDebug()<<myWebSocket.isValid()<<myWebSocket.state();
                      
                      }
                      
                      MainWindow::~MainWindow()
                      {
                          delete ui;
                      }
                      
                      void MainWindow::on_testButton_clicked()
                      {
                          qDebug()<<myWebSocket.isValid()<<myWebSocket.state()<<myWebSocket.error();
                      }
                      

                      Debug return:
                      false QAbstractSocket::UnconnectedState QAbstractSocket::UnknownSocketError
                      false QAbstractSocket::UnconnectedState QAbstractSocket::UnknownSocketError
                      false QAbstractSocket::UnconnectedState QAbstractSocket::UnknownSocketError
                      false QAbstractSocket::UnconnectedState QAbstractSocket::UnknownSocketError

                      Why can't I even use the example "SslEchoClient" to connect to the websocket?

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #14

                      @Mikeeeeee DO YOU HAVE ANY ERRORS WHEN TRYING TO CONNECT? After calling myWebSocket.open(QUrl(myUrl).
                      Did you connect a slot to https://doc.qt.io/qt-5/qwebsocket.html#error-1 as I suggested?
                      Is your onSslErrors called?

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      2
                      • M Offline
                        M Offline
                        Mikeeeeee
                        wrote on last edited by
                        #15

                        I did, but debag doesn't say it was a error:

                            myUrl = "wss://ws.binaryws.com/websockets/v3?app_id=xlY2chJRk0XoSL5";
                            myWebSocket.open(QUrl(myUrl));
                            //myWebSocket
                            qDebug()<<myWebSocket.isValid()<<myWebSocket.state();
                            connect(&myWebSocket, QOverload<QAbstractSocket::SocketError>::of(&QWebSocket::error),
                                [=](QAbstractSocket::SocketError error){ qDebug()<<"i have error";});
                        

                        Example "SslEchoClient" also no message, means no error, but the websocket is not connected.

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          Mikeeeeee
                          wrote on last edited by
                          #16

                          Do you have an example of "SslEchoClient" connecting to a websocket?

                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            Mikeeeeee
                            wrote on last edited by
                            #17

                            Found this code. It is similar to worker.
                            You do not know any besoket on which it is possible to check operability?

                            1 Reply Last reply
                            0
                            • M Offline
                              M Offline
                              Mikeeeeee
                              wrote on last edited by
                              #18

                              If I use the program with GitHub, I get an error: "WebSocket::processHandshake: Unhandled http status code 301"
                              Please tell me why and how to fix it?

                              jsulmJ 1 Reply Last reply
                              0
                              • M Mikeeeeee

                                If I use the program with GitHub, I get an error: "WebSocket::processHandshake: Unhandled http status code 301"
                                Please tell me why and how to fix it?

                                jsulmJ Offline
                                jsulmJ Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on last edited by
                                #19

                                @Mikeeeeee If you use Google to search for "http 301" you will find https://en.wikipedia.org/wiki/HTTP_301 which tells you that 301 status code means "Moved Permanently is used for permanent URL redirection". What URL are you using?

                                https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                1
                                • M Offline
                                  M Offline
                                  Mikeeeeee
                                  wrote on last edited by Mikeeeeee
                                  #20

                                  Trying to connect to websocket "wss://ws.binaries.com/websockets/v3?app_id=1089".
                                  Yesterday, he was connected here, and today is not connected.
                                  Apparently he works on a certain time.

                                  1 Reply Last reply
                                  0
                                  • M Offline
                                    M Offline
                                    Mikeeeeee
                                    wrote on last edited by
                                    #21

                                    It looks like the bug of websocket. I connect to other web sites.

                                    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