QtQuick QML SQL C++ - 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.

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

QT, c++ dlls, and objects

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!

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.

Need guidance in non C/C++ based graphics interface

I have prepared a program launcher in C++ (the only language I know), which accepts strings as program trigger.
But however hard I try I'm unable to give it a GUI like look; using graphics.h's graph functions creates graphics but in cmd like window.
All I need is a small widget/window like thing that sits on the desktop where a user can type the command string (and error messages can be displayed as usual).
Can I get a code snippet for such a widget/window?
The input string may be copied to a .txt file and my prog will read it from there.
P.S.- I'm a beginner & rookie so please avoid complex alternatives.
Well, one of the easiest options in my opinion is to use .NET Framework:
http://10rem.net/blog/2010/03/04/my-first-windows-cplusplus-application-in-ages-hello-world-in-win32-with-visual-cplusplus-2010
http://msdn.microsoft.com/en-us/library/bb384845.aspx

How to de-GUI a complex tanglewad C++/Qt4 app?

We have a large messy app written in C++ and Qt4, many library dependencies, hundreds of classes and no coherent structure. It normally runs as a GUI app manipulated interactively, but sometimes it's launched in a hands-off way from another program that feeds it command line options and communicates with it by dbus. The GUI still shows, but no human or trained monkey is there to click anything. "Relaxen und watch das blinkenlights" Whether interactively or automatically, when run the app writes image files.
My job the next few weeks is to add an "no gui" feature, such that the app can run in the hands-off way and write its image files, without ever showing its GUI. Internally, the images to be written are made using QImage and other non-GUI Qt objects, but these are possessed by other objects that do involve the GUI classes of Qt. After several attempts to understand the mess, I cannot find a way to disentangle things such as to have the app create images w/o the whole full-blown GUI running. At one time, I was hoping I could just set xxx.visible= false; for all xxx that are GUI objects, but this is not practical or possible (AFIK).
Are there any general strategies to follow to add this no-gui feature to this app? Some technique that won't require deep redesign of the class hierarchy?
The long and hard way is finding out what and how the logic is executed, extract the logic to some QObject based classes (with signals and slots) and make it a QtCore app. I know this doesn't help, but that's the correct way.
If setting all GUI elements to hidden (or perhaps only the QMainWindow?) is not an option, this is the only thing you can do.
Qt allows you to do this, but if the original coder did not plan this in, you've got a lot of refactoring/recoding to do.
This really depends on how the program is written. If the logic is somewhat seperated from the interface, then it could be as simple as finding out what class inherits from the QMainWindow class and making sure that is never initialised.
In the case where the logic is all over the place, I'd strongly suggest trying to get all the logic into a form of signal or slot (which has probably already happened considering that it's a GUI app), then just not initialising the QMainWindow instance and calling these manually.
Try to subclass interface classes (QMainWindow, QDialog, etc), and implement your logic there.