How to Communication between Qt GUI using qt creator and separate C++ program in visual studio ?
-
wrote on 10 May 2023, 08:18 last edited by
Hello every ,
I want to know how to connect between Qt GUI creator and separate C++ program in visual studio ? -
Hello every ,
I want to know how to connect between Qt GUI creator and separate C++ program in visual studio ?Use any IPC you prefer:
- local socket
- D-Bus (a bit hard to do on Windows but possible)
- RPC
- pipes
- COM
MS even has a special documentation page about this: https://learn.microsoft.com/en-us/windows/win32/ipc/interprocess-communications
-
Use any IPC you prefer:
- local socket
- D-Bus (a bit hard to do on Windows but possible)
- RPC
- pipes
- COM
MS even has a special documentation page about this: https://learn.microsoft.com/en-us/windows/win32/ipc/interprocess-communications
-
@sierdzio
please can you simplify what ipc do ?
as i want to make my code which in visuals studio (it console app)connect with gui I made in qt creator .@Nada-Azab said in How to Communication between Qt GUI using qt creator and separate C++ program in visual studio ?:
@sierdzio
please can you simplify what ipc do ?It allows you to connect 2 separate applications (separate executables) so that they can talk with each other. There is a plethora of solutions (I listed just a few) and it's hard to say which one is best, it depends on situation.
For many (most?) use cases, and especially for a beginner, I'd recommend going with local sockets, they are probably the simplest.
as i want to make my code which in visuals studio (it console app)connect with gui I made in qt creator .
For IPC it does not matter at all which IDE you are using to create the apps.
-
Hello every ,
I want to know how to connect between Qt GUI creator and separate C++ program in visual studio ?wrote on 11 May 2023, 07:57 last edited by@Nada-Azab said in How to Communication between Qt GUI using qt creator and separate C++ program in visual studio ?:
I want to know how to connect between Qt GUI creator and separate C++ program in visual studio ?
If you want this to be one single program first try to join them into a single project. Create either a VS project or a qmake project. Even better today: create a CMake project which can be use simultaneously by Qt Creator and Visual Studio.
Another solution is to make your Visual Studio project a library. A single program can only have a single
main
function. And this has to be the Qt main function! Hence, the VS project needs to be the one without the main. Your Qt project can then call any functions from the VS library project.If you truly want communication between two programs IPC is a good choice. Maybe you are thinking of your VS project as terminal application. In that case it is also possible to use QProcess on the Qt side and launch the C++ program. You can connect to its input and output and communicate using strings. This solution is quick to implement, but not really scalable. Communication using strings is a hassle. If your terminal program is only called from your Qt program you could also just send bytes directly. Still, this is not the best solution.
-
@Nada-Azab said in How to Communication between Qt GUI using qt creator and separate C++ program in visual studio ?:
I want to know how to connect between Qt GUI creator and separate C++ program in visual studio ?
If you want this to be one single program first try to join them into a single project. Create either a VS project or a qmake project. Even better today: create a CMake project which can be use simultaneously by Qt Creator and Visual Studio.
Another solution is to make your Visual Studio project a library. A single program can only have a single
main
function. And this has to be the Qt main function! Hence, the VS project needs to be the one without the main. Your Qt project can then call any functions from the VS library project.If you truly want communication between two programs IPC is a good choice. Maybe you are thinking of your VS project as terminal application. In that case it is also possible to use QProcess on the Qt side and launch the C++ program. You can connect to its input and output and communicate using strings. This solution is quick to implement, but not really scalable. Communication using strings is a hassle. If your terminal program is only called from your Qt program you could also just send bytes directly. Still, this is not the best solution.
wrote on 19 May 2023, 03:51 last edited by Nada Azab@sierdzio
@SimonSchroeder
Thanks for your help. -
wrote on 19 May 2023, 04:19 last edited by
IPC is a generic term for interprocess communications. It is a suite of technologies for message passing between processes that don't share the same memory space.
-
wrote on 19 May 2023, 14:38 last edited by goldenhawking
A funny way to pass messages between processes is the STD pipes, stdin, stdout. You can design a stdin/stdout proxy using QProcess's QIODevice interfaces. This proxy will fork your Qt app and VS app together as child processes, and read data from one's stdin, pass data to another's stdout.
In Win32, text data can be passed directly, while BIN data should be enabled with setmode:
#include <stdio.h> #include <fcntl.h> #include <io.h> int main( ) { // Set "stdin" to have binary mode: _setmode( _fileno( stdin ), _O_BINARY ); //... }
This method enables you to direct use scanf, printf , fread, fwrite for cross-process communication.