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. Connecting a QTcpServer to an existing QtGuiApplication business logic

Connecting a QTcpServer to an existing QtGuiApplication business logic

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 2 Posters 1.6k Views 1 Watching
  • 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
    andcl
    wrote on last edited by andcl
    #1

    I have developed a tiny server using QTcpServer within an old version of Qt, Qt4. It consists of a simple class that serves each request and which I have initialized in main.cpp file, like this:

    #include <QtGui/QApplication>
    #include "mainwindow.h"
    #include "server/server.h"
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
        w.show();
    
        Server server;
    
        return a.exec();
    }
    

    It starts and works fine so far, dealing with TCP sockets and connections. Hello world typical example is working just fine :)

    The problem is that this tiny server is going to be part of a bigger existing Qt4 QtGuiApplication where all the bussiness logic is accessible from MainWindow w class on. Now, as you will expect, I need to "use" (call) that logic (functions, methods, etc.) to compose the responses of my new server, but I can not see how to clearly access that logic from where I am. It is more of an architecture problem, as I see it.

    I have thought that I could use some Qt slots & signals for the communication, but where my Server is initialized, I can not easily link it to that existing internal logic...

    Any ideas of how could it be done?
    Thanks in advance.

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

      Hi and welcome to devnet,

      Looks like there's some drawing needed ;-)

      From an architecture point of view you do not want to have all the business logic coded inside a widget. As you have your Server class, you will also need other pieces to implement that business logic in a nice encapsulated and testable way.

      The various elements will likely end up member variables of the MainWindow but should be separate pieces.

      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
      1
      • A Offline
        A Offline
        andcl
        wrote on last edited by
        #3

        First of all, thanks for the welcome and thanks for the reply.
        I totally agree with you, but I am afraid that I have to tie to the existing application since I do not have access to that code directly.
        I am just looking for a "simple" way to anyhow use the logic without messing up with the current architecture.
        I know you are absolutely right, but I that is not an option for me right now.

        Just to point me in a direction, could you suggest me some approach? i.e., how could I (from my server class) somehow execute or simply call a function or method located in Mainwindow.cpp without messing around?

        Thanks again.

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

          Are you allowed to modify that MainWindow class ?

          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

            Are you allowed to modify that MainWindow class ?

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

            @SGaist Yes. If I ask to, I can do it. Thanks again.

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

              Can you explain what kind of logic should your server trigger ?

              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
              1
              • A Offline
                A Offline
                andcl
                wrote on last edited by andcl
                #7

                Of course, the application itself can be categorized as engineering software.
                Logic basically makes calculations and numeric simulations based on some predefined input values, and some others that come over its GUI, from the user in each case.
                The idea behind the server is to implement an extra channel to serve the results of the application through a web page, receiving those GUI input values through web requests, as an alternative to the current standalone desktop application.

                Thank you again.

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

                  In that case it seems that you would need to split some stuff anyway. Otherwise you will have to have your GUI application running on possibly a headless server. Doable but not really practical.

                  What you could do is split the calculation and business logic in its own library so you can link both the GUI and web version to it.

                  This would be a subdirs project. So you can have everything in one project.

                  There might be other client/server possible architecture but that might be out of scope.

                  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

                    In that case it seems that you would need to split some stuff anyway. Otherwise you will have to have your GUI application running on possibly a headless server. Doable but not really practical.

                    What you could do is split the calculation and business logic in its own library so you can link both the GUI and web version to it.

                    This would be a subdirs project. So you can have everything in one project.

                    There might be other client/server possible architecture but that might be out of scope.

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

                    @SGaist said in Connecting a QTcpServer to an existing QtGuiApplication business logic:

                    Otherwise you will have to have your GUI application running on possibly a headless server

                    Yes, I assume the final deploy will be like that, not very practical, yet valid indeed. Running in a machine with an untouched GUI which also runs the server.
                    Knowing that, could you please suggest me some quite specific approach from where to start trying?
                    Just the one which does not imply that functionality splitting, no matter if it is not a very pragmatic solution...
                    I would appreciate that.
                    Thanks for all.

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

                      I just thought of something, you might be able to avoid the GUI part on the server machine. Pass a parameter to your application so that you can use the web version in place of the GUI version.

                      You can now concentrate on building your web version. The question is: is absolutely everything build within MainWindow or do you have some stuff that you can reuse in the web version ?

                      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
                      1
                      • A Offline
                        A Offline
                        andcl
                        wrote on last edited by
                        #11

                        I am afraid it is all built within MainWindow, and I have to use logic from there.
                        Thanks @SGaist

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

                          Do you mean it's one big massive class that does absolutely everything ?

                          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