QT, c++ dlls, and objects - c++

I'm fairly new to dlls, and completely new to QT. I've been playing for a few days and am trying to create a project wherein I read the contents of a file and display the parsed results neatly. I have written a dll to parse the file format and wish to use that dll within my QT GUI.
My dll contains 4 files, SignalParse.h/cpp and Signal.h/cpp.
SignalParse is the meat of the dll, containing the functionality, and Signal is an object for storing data.
My aim is for my QT program to use this function from within SignalParse:
__declspec(dllexport) vector<Signal> ReturnSignal()
{
return sigList;
}
sigList is a vector containing all the data from my signal objects. Signal data is something like as follows parsed into variables within the signal object:
[SignalOne]
bytes: 2
format: int
offset: 0
The aim behind this is to have the GUI able to access the dll and use it to parse files, then read the parsed data.
However, seeing as I am returning a vector of Signal, I (think I) will need to include signal in my QT project. Is this normal practice? Or should I attempt to store my data in another manner?
As a novice, I'm not sure how to handle situations like this. The idea of storing my signal data in an object seems the neatest, but having to then include the object in every program that uses the dll seems less neat.
Perhaps there is a better way of doing it? I would very much like to know whether my approach is reasonable, or if there is another obvious way of handling this kind of thing that I've blindsided.
Thanks!

Related

Input the output of one program into another program

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

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.

Class Design in C++ program

I'm currently working on a little project in C++. I'm fairly new to C++/Programming and wanted to ask how my classes should be designed.
To be specific: I want to write a little program for chatting. Just simple communication between two programs/computers. For that I want to use a good class design because, although it is only a small project (just for the sake of learning), I want it to be well designed and extensible.
My program should have about 5 classes (Handlers etc, the Updater and App - the main class only for this program).
I'll give you a few examples of ideas I have how I could design one part of the program. The first part should be the connection part (handled by Connection). The task is to build up a connection between the two programs. It will also set up local files, which will hold the information to print, and connect it to the 'server' file. Later in the program there should be access to the File_Handler class so it can edit/read the local file and read/request to write to the 'server' file. (How exactly it's gonna do it is already figured out, so as long as it is not necessary I'd like to keep this system as it is ;) ). But now let's get to the ideas I have:
Idea 1
App creates an instance of Connection to set up the connection.
Connection then creates an instance of File_Handler which will set up the files (in this case File_Hanlder would hold the paths with static variables) and then destroy that instance because it is no longer needed by Connection.
Another class (instance is held by App) then creats an own instance of File_Hanlder later and could work with the files since the variable for the path is static.
Idea 2
App creates an Instance of Connection and File_Handler (lets call them con and fil).
To set up the connection, fil is passed per reference to con to set up the variable paths for the files and create the files etc. .
For working with the files later, App would pass around fil to manage all the file handling for the other classes which would, for example, update the chat etc.
That would require a lot of classes to have a constructor or (a) function(s) which needs to have a File_Handler parameter and the same variable would be passed around a lot of times.
Idea 3
The last idea I have is that Connection, File_Handler and the other classes would be created very general without any or near to zero relation to other classes.
App then creates a lot of functions (or even 'subclasses') to work with these classes almost like working with Frameworks which were developed independently and thus could, theoraticly, be used in another program without any problems.
Which solution do you think would be the best? Or is there another solution you have for me which would be even better?

Convert Win32 Application to Object

I'm pretty new to WinAPI programming, and have written a Win32 application for screen capture. When I run the program, the cursor immediately changes to a crosshair and I can click and drag to capture a portion of the screen and save it to file.
However, I'd now like to modify my program so that it doesn't contain a main method (WinMain) and essentially turn it into an object class rather than an application class so I can call functions from other programs. I haven't been able to find a good resource on how to do this, as I believe WinMain carries out special functionality under the hood so I can't simply change the name of the method.
Can anyone suggest some good resources or tutorials that address this?
There are many ways to do that, but you have fist move one step back:
How do yopu expect your "program" (let us continue to call that way) to be called?
With which parameters and what return type?
Then, what kind of API do you want to expose? A C++ class in header? a C++ class from a static library?
A C function exported from a DLL? an COM object?
There are many sample on how a library or a DLL or a COM library looks like (just try google those keywords).
The simple way is most likely to set up a library or a DLL project (most IDE have wizard that provide empty skeletons), than paste in it the relevant code that you require to leave there, letting it be called from the exposed function or class method.
A more precise answer can be given only after you decided which "form" your "object" should have.

Retrieving GUI Objects from another process

I want to retrieve a GUI Object so that I can read and modify they Object.
Right now the only way I can think of to do this is via injection (where the injection does a lot of the retrieving of the data and sends back what I want). My problem with injection is that I cannot easily debug it and it takes a long time to figure out what to do.
I can find the handle of the GUI object so is there a way i can use ReadProcessMemory() or something like this so that I can read the memory in another process and from this build it up into the GUI object that I want?
Assuming you have the proper permissions and have some way to obtain the window handle (HWND) of a specific GUI object (see FindWindow()), you can call regular Win32 API functions such as SetWindowText() to modify the contents of those GUI objects.
However, doing this can break the other process' logic! If the process that owns the GUI object has cached some information and you modify the source behind its back, you might not get the desired effect.