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. QHttpServer, where is it?

QHttpServer, where is it?

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 5 Posters 3.5k 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #1

    Is there anything specific I need to do to enable QHttpServer, I found details which says its part of Qt, however I cannot find any QHttpServer header ?

    Kind Regards,
    Sy

    Pablo J. RoginaP 1 Reply Last reply
    0
    • SPlattenS SPlatten

      I've implemented QTcpServer in my application and this "worked" fine, I want to modify it so the response is managed by a thread as its quite possible to get multiple requests simultaneously and I don't want the application to wait around dealing with requests individually.

      void clsSocketServer::readClient() {
          enum {
              REQ_METHOD = 0
             ,REQ_DATA
          };
          QTcpSocket* pSckClient = (QTcpSocket*)sender();
      
          if (!pSckClient->canReadLine() ) {
              return;
          }
          QStringList slstTokens = QString(pSckClient->readLine()).split(QRegExp("[ \r\n][ \r\n]*"));
      
          if ( slstTokens[REQ_METHOD] != "GET" ) {
              return;
          }
          QString strRequest = slstTokens[REQ_DATA];
          int intIdx = strRequest.indexOf(clsJSON::msccOpenCurlyBracket);
      
          if ( intIdx >= 0 && strRequest[strRequest.length() - 1] == clsJSON::msccCloseCurlyBracket ) {
          //Skip to start of JSON
              strRequest = strRequest.mid(intIdx);
          //Translate request, converting escaped characters
              strRequest = QUrl::fromPercentEncoding(strRequest.toLatin1());
          //Create JSON object
              clsJSON objJSON(&strRequest);
      
              if ( objJSON.blnIsValid() == true ) {
          //Set-up response stream
                  QTextStream tsResponse(pSckClient);
                  tsResponse.setAutoDetectUnicode(true);
          //Create thread to deal with request and send response
                  std::thread* pthdCliHelper = new std::thread(clsSocketServer::manageRequest
                                                              ,&objJSON, &tsResponse);
                  if ( pthdCliHelper != nullptr ) {
                      pthdCliHelper->join();
                  }            
              }
          }
          /*NOTE: Do not close connection, once established connections between modules and server
           *      stay open until the server dies!
          pSckClient->close();
      
          if (pSckClient->state() == QTcpSocket::UnconnectedState) {
              delete pSckClient;
          }*/
      }
      

      I can see that the request is being received and the "manageRequest" is dealing the response, however this doesn't make it to the client...I'm using a web-browser as the client to test.

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

      @SPlatten said in QHttpServer, where is it?:

      I've implemented QTcpServer in my application and this "worked" fine, I want to modify it so the response is managed by a thread as its quite possible to get multiple requests simultaneously and I don't want the application to wait around dealing with requests individually.

      There's the Threaded Fortune Server Example

      Should get you started 😉


      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
      3
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        google is your friend: https://github.com/qt-labs/qthttpserver

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

        SPlattenS 1 Reply Last reply
        0
        • SPlattenS SPlatten

          Is there anything specific I need to do to enable QHttpServer, I found details which says its part of Qt, however I cannot find any QHttpServer header ?

          Pablo J. RoginaP Offline
          Pablo J. RoginaP Offline
          Pablo J. Rogina
          wrote on last edited by
          #3

          @SPlatten said in QHttpServer, where is it?:

          QHttpServer,

          If you refer to this QHttpServer it seems deprecated.

          You may want to look at new Qt Http Server provided as module from Qt, see this post. Be aware of the GPL license just in case.

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            google is your friend: https://github.com/qt-labs/qthttpserver

            SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by
            #4

            @Christian-Ehrlicher , to be honest its not really what I want anyway, I'm just looking for some good tutorials on how to use QTcpServer and QTcpSocket.

            Kind Regards,
            Sy

            Pablo J. RoginaP Christian EhrlicherC 2 Replies Last reply
            0
            • SPlattenS SPlatten

              @Christian-Ehrlicher , to be honest its not really what I want anyway, I'm just looking for some good tutorials on how to use QTcpServer and QTcpSocket.

              Pablo J. RoginaP Offline
              Pablo J. RoginaP Offline
              Pablo J. Rogina
              wrote on last edited by
              #5

              @SPlatten said in QHttpServer, where is it?:

              looking for some good tutorials on how to use QTcpServer and QTcpSocket.

              So why don't you use that sentence as the title of your post?

              Upvote the answer(s) that helped you solve the issue
              Use "Topic Tools" button to mark your post as Solved
              Add screenshots via postimage.org
              Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              1
              • SPlattenS SPlatten

                @Christian-Ehrlicher , to be honest its not really what I want anyway, I'm just looking for some good tutorials on how to use QTcpServer and QTcpSocket.

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @SPlatten said in QHttpServer, where is it?:

                how to use QTcpServer and QTcpSocket.

                Now QTcpServer ? Please clarify what you really want...
                For QTcpServer the documentation has some examples.

                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
                0
                • SPlattenS Offline
                  SPlattenS Offline
                  SPlatten
                  wrote on last edited by
                  #7

                  I've implemented QTcpServer in my application and this "worked" fine, I want to modify it so the response is managed by a thread as its quite possible to get multiple requests simultaneously and I don't want the application to wait around dealing with requests individually.

                  void clsSocketServer::readClient() {
                      enum {
                          REQ_METHOD = 0
                         ,REQ_DATA
                      };
                      QTcpSocket* pSckClient = (QTcpSocket*)sender();
                  
                      if (!pSckClient->canReadLine() ) {
                          return;
                      }
                      QStringList slstTokens = QString(pSckClient->readLine()).split(QRegExp("[ \r\n][ \r\n]*"));
                  
                      if ( slstTokens[REQ_METHOD] != "GET" ) {
                          return;
                      }
                      QString strRequest = slstTokens[REQ_DATA];
                      int intIdx = strRequest.indexOf(clsJSON::msccOpenCurlyBracket);
                  
                      if ( intIdx >= 0 && strRequest[strRequest.length() - 1] == clsJSON::msccCloseCurlyBracket ) {
                      //Skip to start of JSON
                          strRequest = strRequest.mid(intIdx);
                      //Translate request, converting escaped characters
                          strRequest = QUrl::fromPercentEncoding(strRequest.toLatin1());
                      //Create JSON object
                          clsJSON objJSON(&strRequest);
                  
                          if ( objJSON.blnIsValid() == true ) {
                      //Set-up response stream
                              QTextStream tsResponse(pSckClient);
                              tsResponse.setAutoDetectUnicode(true);
                      //Create thread to deal with request and send response
                              std::thread* pthdCliHelper = new std::thread(clsSocketServer::manageRequest
                                                                          ,&objJSON, &tsResponse);
                              if ( pthdCliHelper != nullptr ) {
                                  pthdCliHelper->join();
                              }            
                          }
                      }
                      /*NOTE: Do not close connection, once established connections between modules and server
                       *      stay open until the server dies!
                      pSckClient->close();
                  
                      if (pSckClient->state() == QTcpSocket::UnconnectedState) {
                          delete pSckClient;
                      }*/
                  }
                  

                  I can see that the request is being received and the "manageRequest" is dealing the response, however this doesn't make it to the client...I'm using a web-browser as the client to test.

                  Kind Regards,
                  Sy

                  J.HilkJ 1 Reply Last reply
                  0
                  • SPlattenS SPlatten

                    I've implemented QTcpServer in my application and this "worked" fine, I want to modify it so the response is managed by a thread as its quite possible to get multiple requests simultaneously and I don't want the application to wait around dealing with requests individually.

                    void clsSocketServer::readClient() {
                        enum {
                            REQ_METHOD = 0
                           ,REQ_DATA
                        };
                        QTcpSocket* pSckClient = (QTcpSocket*)sender();
                    
                        if (!pSckClient->canReadLine() ) {
                            return;
                        }
                        QStringList slstTokens = QString(pSckClient->readLine()).split(QRegExp("[ \r\n][ \r\n]*"));
                    
                        if ( slstTokens[REQ_METHOD] != "GET" ) {
                            return;
                        }
                        QString strRequest = slstTokens[REQ_DATA];
                        int intIdx = strRequest.indexOf(clsJSON::msccOpenCurlyBracket);
                    
                        if ( intIdx >= 0 && strRequest[strRequest.length() - 1] == clsJSON::msccCloseCurlyBracket ) {
                        //Skip to start of JSON
                            strRequest = strRequest.mid(intIdx);
                        //Translate request, converting escaped characters
                            strRequest = QUrl::fromPercentEncoding(strRequest.toLatin1());
                        //Create JSON object
                            clsJSON objJSON(&strRequest);
                    
                            if ( objJSON.blnIsValid() == true ) {
                        //Set-up response stream
                                QTextStream tsResponse(pSckClient);
                                tsResponse.setAutoDetectUnicode(true);
                        //Create thread to deal with request and send response
                                std::thread* pthdCliHelper = new std::thread(clsSocketServer::manageRequest
                                                                            ,&objJSON, &tsResponse);
                                if ( pthdCliHelper != nullptr ) {
                                    pthdCliHelper->join();
                                }            
                            }
                        }
                        /*NOTE: Do not close connection, once established connections between modules and server
                         *      stay open until the server dies!
                        pSckClient->close();
                    
                        if (pSckClient->state() == QTcpSocket::UnconnectedState) {
                            delete pSckClient;
                        }*/
                    }
                    

                    I can see that the request is being received and the "manageRequest" is dealing the response, however this doesn't make it to the client...I'm using a web-browser as the client to test.

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

                    @SPlatten said in QHttpServer, where is it?:

                    I've implemented QTcpServer in my application and this "worked" fine, I want to modify it so the response is managed by a thread as its quite possible to get multiple requests simultaneously and I don't want the application to wait around dealing with requests individually.

                    There's the Threaded Fortune Server Example

                    Should get you started 😉


                    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
                    3
                    • Chris BC Offline
                      Chris BC Offline
                      Chris B
                      wrote on last edited by
                      #9

                      It has been deprecated, but you can also look at libmicrohttpd, it is a small footprint HTTP server implementation. Some good libraries have been built on it such as https://github.com/etr/libhttpserver to implement REST, etc.. Although they are standard C++, you can certainly use QT inside them.

                      1 Reply Last reply
                      1

                      • Login

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