Need to create a Graphical Interface for a C++ CLI Application
-
Hello i am trying to create a Gui for a CLI application and i have the limitation that i cant change the source code or add to QT so i chose to do it by using Sockets.
Questions:- I want to create a c++ class with the sockets and the logic of the simulator there and i update the QML from there. Which approach is better?
a. Create a new thread and run it simultaneously with the qui?
b. I found how to change the properties from main.cpp but i cant make it work from different cpp class
code i used:(i understand the code from main.cpp but i didnt find anything helpful when i want to do it from different class)
@QObject *rootObject = engine.rootObjects().first();
QObject qmlObject = rootObject->findChild<QObject>("rect");
rootObject->setProperty("visible", true);
qmlObject->setProperty("color", "yellow");@
c. Is it better to instantiate the whole GUI from c++?
I am kinda confused i try alot of stuff but i am not sure which is correct. Till now i try the socket part and did some of the gui so i need to figure out how to process the data from application send by sockets and then change attributes of gui(for starter i want to try changing shape's colors )
Thanks in advance!
- I want to create a c++ class with the sockets and the logic of the simulator there and i update the QML from there. Which approach is better?
-
Hi,
What kind of information are you exchanging with that CLI application ?
-
Hello,
I will need to exchange strings and integers from the cli Application and i will need to process those information before i change the attributes in Gui. Basically the CLI application is a NOC simulator and i need to show how the packets are traversing the network.
Thanks in advance -
Then as your wrote you should first create a class that will handle the communication with your simulator.
Then you can pass an instance of that class to your QML GUI and handle things there.
That would be the most straightforward.
Does that simulator run on his own or do you need to start it from your GUI application ?
Does it offer other channels of communication ? -
Thats helpful, and is it better to instantiate QML from c++ or just send information to qml and use some logic there to change qml?
Simulator run on his own and yes i prefer to start it from Gui by creating new process and run a terminal. No it doesnt offer other channels of communication..
Thank you in advance -
Write your GUI as usual, then in your main function, create your "controller" object and pass it to QML where you'll be doing whatever connection is needed.
-
I think i got the main idea and thank you very much for the support. I will start from the CLI APPlication and use command line to print the data and the continue with the GUI.
Something to close the topic,the controller that i will create it will consists with alot of connections is a class ? an object and do you have anything for reference? or an example?
Something like this?
https://www.wisol.ch/w/articles/2014-12-15-qt-signal-slots-qml-cpp/Thank you in advance
-
Yes but please use better naming ;)
You can also take a look at the Integrating QML and C++ chapter of Qt's documentation.