Input the output of one program into another program - c++

I am trying to make a billing software for which I need to take the output of one cpp program as an input in the second program.
eg:
In program 1, the user chose multiple things which made the to the value 'bill'=100.
I need Program 2 to read the value of 'bill' which was 100 in the end of program 1, and then add/subtract whatever the user does to this (interger?) and print the final value in the end of program #2..
I don't know if i explained it correctly but you can take a rough idea of what I meant..

As mentioned in the comments, there are many alternatives. However, I do not suggest the solutions like writing out to a file and reading from another program because you can face with problems like synchronization issues while accessing the file or bottleneck issues (may not be issue in this case but it may happen during big data transfers) regarding file I/O performance. Using mechanisms such as pipes or sockets would be a better solution.
If your software is using Qt Framework, I recommend using Qt Remote Objects. Both PyQt and Qt with C++ support QtRO communication.
In QtRO, the objects can be shared between applications through a defined interface. The source node (program 1) shares the object that contains bill. The clients can access the replicas of the shared object and get properties. When the replica is received, it can be used like any other QObject.
For more information about Qt Remote Objects check out: https://doc.qt.io/qt-6/qtremoteobjects-index.html

Related

QtQuick QML SQL C++

I need to run an algorithm in Qt on data that originates from two different sources:
1- UART ( raw transducer data)
2- variables a user inputs into a gui
The result is then output to the gui for the user to see
Gameplan:
- User inputs variables via a gui (written in qml - i actually have no choice on this)
- The qml creates a database of all variables, then
- Invokes C++ routines for collecting raw data over a UART , saves it to a file,
- the C++ module opens up the database and extracts variables needed , opens the file reads in the data, runs the algorithm using both, calculates the answer and writes it to the database,
- program then jumps back to QML where, later, the QML will go into the database to extract that answer and display it.
If you see a flaw already please let me know before I spend hours finding out this wont work. If it is plausible.....
FOUR QUESTIONS:
(1) who should run the UART - C++ or QML? anyone knows pros /cons? The raw data will have to be post processed so i'm thinking it will need file saving (I'm thinking UART is a C++ thing)
(2) I need to create a database from user input variables from QML - any one have examples of this?
(3) - the QML must do a Q_INVOKABLE to the C++ routines (to run the algorithm) . I've already run a test program to prove I can do that so not too worried though if anyone has any other examples I'd love to see how others do this.
(4) BOTH the QML and the C++ need to access (read and write) the database created in (2).
Is this doable? If so...anyone have any examples of QML and C++ sharing the same database, any code, videos, anything? Should I keep opening and closing the database or is there a way to open it and have some pointer or something be passed around. I can't find anything about QML accepting or passing a pointer.
Thanks
Dubs
(using ARM® Cortex™-A9 embedded linux qt)
For SQL and QML Q_INVOKABLE refer to this answer and for UART use C++ and invoke it from QML.

Creating a Launcher and sending info to second program

I have created a program that extracts data from a racing game and sends it to a speed gauge cluster. I call it the transfer program.
I need a simple user-friendly User Interface to start the transfer program, set some variables and choose a COM Port. At the moment I'm trying to do it with a C++ Windows Forms Application in a CLR Project on Microsoft Visual Studio 2015. When I tried to do it directly (creating the UI in the same project as the transfer program) I just get too many errors that I have no idea where they come from or why they are there.
So I've decided maybe I could try creating some sort of launcher, i.e. a completely different program that is only the UI to start the transfer program and send a few user-set variables to it on startup as well as choose a COM Port to communicate on.
Any idea on how to start on this? How do I execute the transfer program from the Launcher? How do I send variables and data to it?
Thank you very much!
There are basically two ways to pass information to your transfer program.
For simple use cases, just pass the values along on the command line. If you're still using the CLR, this is done using System.Diagnostics.Process. A nice example can be found in this answer: https://stackoverflow.com/a/33633148/127826
Use a shared configuration file. So the user interface loads the values from the config and also saves the file before executing the transfer program. The transfer program then reads the same configuration file to get the values it needs.
The second approach is far more flexible and is what I would use.

How to determine an order of opening files for a process?

Is there a way to get all opened file handles for a process and arrange it by time files were opened? We have a project, which requires exactly this - we need to determine which files are opened by a Dj software, such as Traktor or Serato. The reason we need to know its order is to determine, which file is in the first deck, and which is in the second one.
Currently we are using Windows internal APIs from the Ntdll.dll (Winternl.h) to determine a list of all opened files for a process. Maybe that's not the best way to do it. Any suggestions are highly appreciated.
We relied on an observed behavior of that APIs on certain OS version and certain Dj software versions, which was that the list of all opened files for a process never get rearranges, i.e. adheres an order. I know that's a bad practice, but it was a "should be" feature from the customer right before the release, so we had to. The problem is now we have a bug when those handles are sometimes randomly rearranged without any particular cause. That brakes everything. I thought maybe there would be a field in those win structures to obtain file's been opened time, but seemingly there are no such things. Docs on that APIs are quite bad.
I thought about some code paste, but it's a function 200 lines long and it uses indirect calls from the dll using function pointers and all structures for WinAPIs are redefined manually, so it's really hard to read it. Actually, the Winternl.h header isn't even included - all stuff is loaded manually too, like that:
GetProcAddress( GetModuleHandleA("ntdll.dll"), "NtQuerySystemInformation" );
It's really a headache for a cross platform application...
P.S. I have posted a related question here about any cross-platform or Qt way to get opened file handles, maybe that stuff will be useful or related.
if it's just to check the behavior in other OS for debug purpose, you can use the technique of creating process in debug mode and intercept in the order all events of dll loading, here's a good article talking about that.

Two applications reading and writing to the same file, how to prevent crashes or missing data on reads?

I am writing two applications: one to write data to a file and another to read data from a file. These programs will be running at the same time. My fear is that one app might write to the file some data and then the other app tries to read it before it is finished. This may lead to missing data, scrambled data, or crashes.
Not sure what I can do... is there a way to lock the file while in use(set from each app)?
(Note: I will not be using a database.)
I am using VS C++ 6.0... this is one of the companies requirements due to older software.
You should use some kind of synchronization between the two processes. For example create a named event (CreateEvent with a lpName that is not NULL). Initialize the event to
CreateEvent(NULL /*lpEventAttributes*/, FALSE /*bManualReset*/, TRUE /*bInitialState*/, "AnyUniqueNameThatYouChoose"/*lpName*/);
This way when one of the process wants to use the file it should first WaitForSignleObject on the event. When it is done it should SignalEvent thus allowing the other process to access the file.
BTW - VC6 is a really bad compiler. You should consider upgrading to a newer version.

Reading Data From Another Application

How do I read data from another window's application?
The other application has a TG70.ApexGridOleDB32 according to Spy++. It has 3 columns and a few rows. I need to read this data from another application I am writing. Can someone help me?
I am writing the code in MFC/C++
Operating systems donot allow directly reading data from different applications/processes. In case your "application" is a sub-process of main application, you can use shared objects to pass data to and fro.
However, in your case, it seems like the most appropriate would be to dump your data on disk. Suppose you have applications A and B. So B can generate the data and push this data onto a regular file or a database. Then A can access the file/database to proceed. Note that this will be a very costly implementation because of sheer number of I/Os performed.
So if your application is generating a lot of data, making both the applications as threads would be the way to go.