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.
Forum Updated to NodeBB v4.3 + New Features

Design pattern for GUI and NON GUI mode.

Scheduled Pinned Locked Moved Unsolved General and Desktop
44 Posts 7 Posters 9.1k Views 3 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 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