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 should I design my app to meet this criteria ?
Forum Updated to NodeBB v4.3 + New Features

How should I design my app to meet this criteria ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 2 Posters 855 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.
  • P Offline
    P Offline
    pingal
    wrote on last edited by
    #1

    NOTE: This is a NON-GUI app

    I've wrote an HTTP upload/download class using QNetworkAccessManager and i use it like below:-

    int main(..){
    
       QCoreApplication app(...);
        HTTP http(&app);
    
        QNetworkRequest DownloadRequest;
        QNetworkRequest UploadRequest;
    
        UploadRequest.setUrl(QUrl("path/to/server"));
    
        http.UploadFile(UploadRequest, (QFileInfo)"path/to/file1");
        http.UploadFile(UploadRequest, (QFileInfo)"path/to/file2");
        http.UploadFile(UploadRequest, (QFileInfo)"path/to/file3");
    
        DownloadRequest.setUrl(QUrl("link/to/fileX"));
        http.DownloadFile(DownloadRequest);
        
        app.exec();
    
    }
    

    This works fine and now I want to embed this module in another project which is a client app constantly communicating with my server app. So I created a std::thread (not a Qthread) and moved QCoreApplication & app.exec() to avoid being paused in the event loop like below

    int main(..){
    
     std::thread UploadDownloadModule(..);   // this contains the upload/download and app.exec
    
    // do some stuff here
    
    }
    

    This works fine but I want UploadDownloadModule(..) to get finished once the download/upload process completes. I would also like to invoke UploadDownloadModule(..) on request.

    How should I design my app to meet the above criteria?

    jsulmJ 1 Reply Last reply
    0
    • P pingal

      NOTE: This is a NON-GUI app

      I've wrote an HTTP upload/download class using QNetworkAccessManager and i use it like below:-

      int main(..){
      
         QCoreApplication app(...);
          HTTP http(&app);
      
          QNetworkRequest DownloadRequest;
          QNetworkRequest UploadRequest;
      
          UploadRequest.setUrl(QUrl("path/to/server"));
      
          http.UploadFile(UploadRequest, (QFileInfo)"path/to/file1");
          http.UploadFile(UploadRequest, (QFileInfo)"path/to/file2");
          http.UploadFile(UploadRequest, (QFileInfo)"path/to/file3");
      
          DownloadRequest.setUrl(QUrl("link/to/fileX"));
          http.DownloadFile(DownloadRequest);
          
          app.exec();
      
      }
      

      This works fine and now I want to embed this module in another project which is a client app constantly communicating with my server app. So I created a std::thread (not a Qthread) and moved QCoreApplication & app.exec() to avoid being paused in the event loop like below

      int main(..){
      
       std::thread UploadDownloadModule(..);   // this contains the upload/download and app.exec
      
      // do some stuff here
      
      }
      

      This works fine but I want UploadDownloadModule(..) to get finished once the download/upload process completes. I would also like to invoke UploadDownloadModule(..) on request.

      How should I design my app to meet the above criteria?

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

      @pingal said in How should I design my app to meet this criteria ?:

      I want to embed this module in another project which is a client app

      Is this app a Qt app?

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

      P 1 Reply Last reply
      0
      • jsulmJ jsulm

        @pingal said in How should I design my app to meet this criteria ?:

        I want to embed this module in another project which is a client app

        Is this app a Qt app?

        P Offline
        P Offline
        pingal
        wrote on last edited by pingal
        #3

        @jsulm

        The above is a QT app but the project in which i want to embed is NOT a QT App

        jsulmJ 1 Reply Last reply
        0
        • P pingal

          @jsulm

          The above is a QT app but the project in which i want to embed is NOT a QT App

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

          @pingal You could pass UploadDownloadModule a callback function, so it can call it when its finished and pass the result to this callback. To invoke UploadDownloadModule you can simply create a new UploadDownloadModule instance passing needed parameters to it.

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

          P 1 Reply Last reply
          0
          • jsulmJ jsulm

            @pingal You could pass UploadDownloadModule a callback function, so it can call it when its finished and pass the result to this callback. To invoke UploadDownloadModule you can simply create a new UploadDownloadModule instance passing needed parameters to it.

            P Offline
            P Offline
            pingal
            wrote on last edited by pingal
            #5

            @jsulm :
            What about the app.exec() in the callback ?

            jsulmJ 1 Reply Last reply
            0
            • P pingal

              @jsulm :
              What about the app.exec() in the callback ?

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

              @pingal said in How should I design my app to meet this criteria ?:

              What about the app.exec(..) in the callback ?

              Why in call back?
              app.exec() will be started in the thread.
              As soon as the thread finishes it call the call back.

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

              P 1 Reply Last reply
              0
              • jsulmJ jsulm

                @pingal said in How should I design my app to meet this criteria ?:

                What about the app.exec(..) in the callback ?

                Why in call back?
                app.exec() will be started in the thread.
                As soon as the thread finishes it call the call back.

                P Offline
                P Offline
                pingal
                wrote on last edited by pingal
                #7

                @jsulm Would you be kind enough to provide me an example (i think i'm not getting you) keeping in view the above picture I gave (?)

                Here is the simplified form of my thread function

                void UploadDownload() {
                    QCoreApplication app(a, nullptr);
                    HTTP http(&app);
                
                    QNetworkRequest DownloadRequest;
                    DownloadRequest.setUrl(QUrl("link/to/fileX"));
                    http.DownloadFile(DownloadRequest);
                
                    app.exec();
                
                }
                
                jsulmJ 1 Reply Last reply
                0
                • P pingal

                  @jsulm Would you be kind enough to provide me an example (i think i'm not getting you) keeping in view the above picture I gave (?)

                  Here is the simplified form of my thread function

                  void UploadDownload() {
                      QCoreApplication app(a, nullptr);
                      HTTP http(&app);
                  
                      QNetworkRequest DownloadRequest;
                      DownloadRequest.setUrl(QUrl("link/to/fileX"));
                      http.DownloadFile(DownloadRequest);
                  
                      app.exec();
                  
                  }
                  
                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by jsulm
                  #8

                  @pingal Untested

                  void callBack()
                  {
                      std::cout << "Done" << std::endl;
                  }
                  
                  typedef void(*CallBack)();
                  void UploadDownload(CallBack callBack)
                  {
                      // Do the work
                      ...
                      app.exec();
                      // When done call call back
                      callBack();
                  }
                  
                  std::thread thread(UploadDownload, callBack);
                  

                  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