Design pattern for GUI and NON GUI mode.
-
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.@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. -
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?
-
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?
@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.
-
I am using std::thread to invoke a QCoreApplication event loop. Here is my code
DLL.hSharedLibrary *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?