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. Design pattern for GUI and NON GUI mode.
QtWS25 Last Chance

Design pattern for GUI and NON GUI mode.

Scheduled Pinned Locked Moved Unsolved General and Desktop
44 Posts 7 Posters 7.2k 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.
  • A Offline
    A Offline
    Ayush Gupta
    wrote on last edited by
    #33

    sorry it is so confusing for me.

    I have to create a QT application (in both GUI and NON-GUI) mode.... and my QT application should be in dll which will launch by other console application.

    So means creating two dlls for core and GUI and (core dll should launch) GUI dll ?

    and in NON-GUI mode the core dll should not launch GUI dll?

    and the commuincation between core dll and GUI dll will be using IPC?

    A 1 Reply Last reply
    0
    • SGaistS SGaist

      As I already suggest, you really should consider using IPC rather making your console application drive a GUI application by hand which will make it not a console application. Apply the Unix mantra: one tool that does its job well.

      See the various possibilities for inter-process communication. Missing there (fix under way), there's also QLocalServer/Socket.

      A Offline
      A Offline
      Ayush Gupta
      wrote on last edited by
      #34

      @SGaist Can you please explain a little bit more?

      1 Reply Last reply
      0
      • A Ayush Gupta

        sorry it is so confusing for me.

        I have to create a QT application (in both GUI and NON-GUI) mode.... and my QT application should be in dll which will launch by other console application.

        So means creating two dlls for core and GUI and (core dll should launch) GUI dll ?

        and in NON-GUI mode the core dll should not launch GUI dll?

        and the commuincation between core dll and GUI dll will be using IPC?

        A Offline
        A Offline
        Astrinus
        wrote on last edited by Astrinus
        #35

        @Ayush-Gupta your design is hopelessly broken and it won't work, you were told that many times (see above posts). And this is not Qt specific (on .NET platform it would be the same, for example). Actually, it could work in a "lite" version, but will break horribly later on, so please FORGET that. Please.
        Please take time to learn about how GUI works in general (message pumps, GUI threads, ...). Completely unrelated to Qt, but studying Win32 API will make you understand A LOT. GUI thread is usually the "main" thread, OS-speaking, so do not mess with displaying GUI in a worker thread.
        So, forget to have a "GUI DLL"; what you mean by this term has no sense whatsoever. Forget completely to have a "application DLL" (means the same as a "white black" or a "near place far, far away").
        Let's recap:

        • You have an existing "console" application that can load a DLL, plugin-like.
        • You want to exchange data between that application and some processing code, bidirectionally.

        One (of many) solution is making a DLL that exposes a socket interface (you could go first by TCP, because is easy to make bidirectional and lossless) and then develop an application (which can run on its own process and do not ever know what application is talking to) that connects to that socket and exchange messages with the other application. You could look into other IPC (inter-process communication) means and select the most suitable for you, since we do not know what application you want talk to, what it does, and what data exchanges, neither we know what you want to do on the other side (headless/GUI).

        Ah, completely forget updating the GUI every 25 ms with a retained mode GUI like Qt (or GTK, or WPF, or Windows Forms, or most GUI frameworks) on a "consumer" system. Your brain does not react so fast to structured information anyway.

        And... better if you pretend threads do not exists. It pays off a lot.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Ayush Gupta
          wrote on last edited by
          #36

          @jsulm @mrjj @Astrinus Still I am struggling with this.
          The requirement is that I have one C++ console application (Non-qt based) which needs to load the DLL (where I should have all business logic of my core application) and I can create a QT GUI application as different process.

          So I am struggling with now if my DLL (which is having business logic) will be loaded an console application (C++) so how can I launch QT GUI application from my DLL application and how can communicate between DLL and my QT GUI application (there will be lot of widgets in my QT application like forms, button, combo box etc.) Every changes in GUI should report to DLL (business logic instantly).

          jsulmJ 1 Reply Last reply
          0
          • A Ayush Gupta

            @jsulm @mrjj @Astrinus Still I am struggling with this.
            The requirement is that I have one C++ console application (Non-qt based) which needs to load the DLL (where I should have all business logic of my core application) and I can create a QT GUI application as different process.

            So I am struggling with now if my DLL (which is having business logic) will be loaded an console application (C++) so how can I launch QT GUI application from my DLL application and how can communicate between DLL and my QT GUI application (there will be lot of widgets in my QT application like forms, button, combo box etc.) Every changes in GUI should report to DLL (business logic instantly).

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

            @Ayush-Gupta said in Design pattern for GUI and NON GUI mode.:

            So I am struggling with now if my DLL (which is having business logic) will be loaded

            Simply link your console application and the GUI application to this DLL, no need to have GUI in business logic DLL.
            "how can communicate between DLL and my QT GUI application" - like you do with any other library.

            https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application
            https://doc.qt.io/qtcreator/creator-project-qmake-libraries.html

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

            1 Reply Last reply
            1
            • A Offline
              A Offline
              Ayush Gupta
              wrote on last edited by
              #38

              @jsulm Sorry If I am not clear.
              My console application will load the business logic during run time (Run time linking). Then I need to launch GUIApplication.exe from DLL.

              Then DLL and GUIApplication.exe should communicate.

              jsulmJ 1 Reply Last reply
              0
              • A Ayush Gupta

                @jsulm Sorry If I am not clear.
                My console application will load the business logic during run time (Run time linking). Then I need to launch GUIApplication.exe from DLL.

                Then DLL and GUIApplication.exe should communicate.

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

                @Ayush-Gupta said in Design pattern for GUI and NON GUI mode.:

                Then I need to launch GUIApplication.exe from DLL

                So, the GUI is NOT part of the DLL, but a stand alone application, right?

                I don't know why you want to load the library at runtime, but if you really need/have to do so then check https://doc.qt.io/qt-5/qlibrary.html

                For IPC (Inter Process Communication) there are many solutions, check https://doc.qt.io/qt-5/ipc.html

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

                1 Reply Last reply
                3
                • A Offline
                  A Offline
                  Ayush Gupta
                  wrote on last edited by
                  #40

                  Yes GUI is not part of DLL.
                  The console C++ application loads the DLL during its initialization of class.
                  If I create GUI as part of DLL then I need to call processEvents from Console Application using DLL interfaces of DLL which cause lot of lags in processing GUI events.

                  I am struggling since lot of days with this design since I am not QT expert I did not find a good relevant design.

                  Basically flow should be like

                  Console application will first load the DLL (having business logic)
                  Then DLL when load and console application will send input to DLL to load the GUI Application.exe
                  And data will be exchange between DLL and console application.
                  And DLL should communicate with GUI application.

                  jsulmJ 1 Reply Last reply
                  0
                  • A Ayush Gupta

                    Yes GUI is not part of DLL.
                    The console C++ application loads the DLL during its initialization of class.
                    If I create GUI as part of DLL then I need to call processEvents from Console Application using DLL interfaces of DLL which cause lot of lags in processing GUI events.

                    I am struggling since lot of days with this design since I am not QT expert I did not find a good relevant design.

                    Basically flow should be like

                    Console application will first load the DLL (having business logic)
                    Then DLL when load and console application will send input to DLL to load the GUI Application.exe
                    And data will be exchange between DLL and console application.
                    And DLL should communicate with GUI application.

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

                    @Ayush-Gupta To start the GUI application from your DLL you can use https://doc.qt.io/qt-5/qprocess.html
                    For loading the DLL and communicating with GUI app I already provided links before.

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

                    1 Reply Last reply
                    1
                    • A Offline
                      A Offline
                      Ayush Gupta
                      wrote on last edited by
                      #42

                      I have tried launching my QT GUI application using QProcess in my DLL it works.
                      Also I have not created any instance of QApplication in my DLL hence no event loop is running in my DLL. I tried to communicate between DLL and QT GUI application by making QTcpServer in DLL and QTcpSocket in QT GUI application but I did not able to make communication successful may be because there is not event loop running in my DLL.

                      So I need to ask if we need to establish communication between QT DLL and QT GUI should I need to create instance of QApplication in DLL also to event loop get running?

                      jsulmJ 1 Reply Last reply
                      0
                      • A Ayush Gupta

                        I have tried launching my QT GUI application using QProcess in my DLL it works.
                        Also I have not created any instance of QApplication in my DLL hence no event loop is running in my DLL. I tried to communicate between DLL and QT GUI application by making QTcpServer in DLL and QTcpSocket in QT GUI application but I did not able to make communication successful may be because there is not event loop running in my DLL.

                        So I need to ask if we need to establish communication between QT DLL and QT GUI should I need to create instance of QApplication in DLL also to event loop get running?

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

                        @Ayush-Gupta said in Design pattern for GUI and NON GUI mode.:

                        if we need to establish communication between QT DLL and QT GUI should I need to create instance of QApplication in DLL

                        Depends on what you use for communication. If you use Qt for that, then yes you need an event loop.

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

                        1 Reply Last reply
                        1
                        • A Offline
                          A Offline
                          Ayush Gupta
                          wrote on last edited by
                          #44

                          I am using std::thread to invoke a QCoreApplication event loop. Here is my code
                          DLL.h

                          SharedLibrary *testShared;
                          std::thread *t;
                          void initDLL()
                          {
                          
                           testShared = new SharedLibrary;
                                  t = new std::thread(&SharedLibrary::init, testShared);
                                  testShared->startProcess();
                                  t->detach();
                                  testShared->startServer();
                          
                          }
                          

                          SharedLibrary.h

                          include <QObject>
                          #include <QThread>
                          #include <QCoreApplication>
                          #include <thread>
                          #include <QProcess>
                          #include "server.h"
                          class Q_DECL_EXPORT SharedLibrary :public QObject    
                          {
                          Q_OBJECT
                          public:
                              SharedLibrary();
                          public:
                              void init();
                              void startProcess();
                              void startServer();
                          
                          private slots:
                          
                              //void onStarted();
                          
                          private:
                          
                              QCoreApplication * app;
                              Server *server_;
                          };
                          

                          ShareLibrary.cpp

                          #include "SharedLibrary.h"
                          SharedLibrary::SharedLibrary()
                          {
                          
                          }
                          
                          
                          
                          void SharedLibrary::init()
                          {
                              char * argv[] = {QString("dummy").toLocal8Bit().data(),NULL};
                              int argc = sizeof(argv) / sizeof(char*) - 1;
                              app = new QCoreApplication(argc, argv);
                              app->exec();
                          }
                          
                          void SharedLibrary::startProcess()
                          {
                              QObject *parent = nullptr;
                              QString program = "./TestPro.exe" ;
                              QStringList arguments;
                              arguments << "test";
                              QProcess *myProcess = new QProcess(parent);
                              myProcess->start(program,arguments);
                              myProcess->write("test",4);
                          }
                          
                          void SharedLibrary::startServer()
                          {
                              server_ = new Server;
                          }
                          

                          Still I am not able to send send data between Test application and DLL using Server and socket.
                          However if intialise the server in function init() it works .

                          It seems event loops exists in function init() only where the thread is created.

                          Is it not possible to make event loop global in class SharedLibrary?

                          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