I have a C++ code and now I am thinking to prepare a UI with Qt since its language is also C++. Before attempting to do that I wonder how can I transfer data between my code and UI code. I mean, I do not want to write variables to a textfile and let UI to read it. Instead I want this to be done internally. I know this is possible but dont know where to start. Any idea?
Asked
Active
Viewed 712 times
0
-
2If your code and the Qt code will be running in the same thread, the standard C++ data-passing approaches (passing via function-call parameter, global variable, etc) should work fine. Or are you planning to have the GUI run as a separate process from the existing code? – Jeremy Friesner Jun 25 '12 at 21:27
-
@JeremyFriesner: Yes, they should work seperately. I dont want to mix them up. – Shibli Jun 25 '12 at 21:36
-
So basically, you're looking for bidirectional interprocess communication in C++. What platforms are you targeting? – cgmb Jun 25 '12 at 21:52
-
Hmm.. Now that I think about it. Is QProcess not sufficient? You could easily invoke your command-line program with whatever arguments you wanted, write to it via standard input, and read back standard output/error. Or, are your communication requirements more complicated than that? – cgmb Jun 25 '12 at 22:02
-
Why do you wnat to run the gui seperately from the other code ? Two threads I would understand but two processes ?? – Martin Jun 25 '12 at 22:32
-
@Martin You can use separate processes - for example: constantly running process as background service (should be small so no qt), and sometimes starting GUI configuration program written with qt. – j_kubik Jun 25 '12 at 22:35
-
Where to start? Perhaps here: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365574%28v=vs.85%29.aspx – j_kubik Jun 25 '12 at 22:37
-
@j_kubik: True but then I would use sockets like e.g. in kismet and then you need a client server structure and this will make quite a complicated setup only worth if you really need it – Martin Jun 25 '12 at 22:46
-
Lots depends on the way apps depend on one another. If one starts another, just use pipes pined to standard streams. If not, use named-pipes. If you don't want to serialize and de-serialize lot's of data, you can use shared memory, but then problems with access synchronization start. – j_kubik Jun 25 '12 at 22:54
2 Answers
1
Qt has a Signal and Slot mechanism that is meant for this purpose. Take a look at the examples here http://qt-project.org/doc/qt-5.0/examples-widgets.html This also works if the Gui runs in a Separate Thread but be careful to get Threading and Signals and Slots right: http://labs.qt.nokia.com/2010/06/17/youre-doing-it-wrong/

Martin
- 4,738
- 4
- 28
- 57
0
For basic communication between a GUI processes and a command-line process, I'd use QProcess. It provides facilities for starting an executable with arguments, reading stdout & stderr, writing to stdin, and notification of program termination. It's cross-platform, and will work with just about anything designed for command-line interaction.

cgmb
- 4,284
- 3
- 33
- 60