Examples¶
Receive and send signals from a QML application¶
This example shows how to create a QML applications and update it using LinX Manager Data Engine to send and receive values from Data Engine.
Prerequisites¶
- A running instance of Data Engine on target device. 
Data Engine is pre-installed on UX Designer VM 4.0. A shortcut is located on the Desktop to start Data Engine with debug flags active.
Create a QML project¶
- Open Qt Creator. 
- File>- New file or Project....
- Select - CrossControl Projectand pick- Qt Quick 2 Application.
- Follow the on-screen instructions to finalize the project creation: - Display resolution: 800x480 
- Kit: Desktop 
 
Create signals for the application¶
- Open LinX Manager Data Engine from the mode selector (left side). 
- Select the created project from the project selector drop-down menu. 
- Create three signals by pressing the add button  . .
- Update the signals with the following information: 
| Name | Data Type | Signal Type | RX Filter | TX Filter | 
|---|---|---|---|---|
| engineRPM | INT | CONSUMER | GLOBAL | GLOBAL | 
| oilPressure | FLOAT | CONSUMER | GLOBAL | GLOBAL | 
| stopEngine | BOOL | PRODUCER | GLOBAL | GLOBAL | 
Update the project¶
- From the projector selector, press “Save” for the changes to take effect. 
- Verify that the project was updated by opening the General Messages tab ( - Alt+6):- LinX Manager Data Engine: Project updated successfully. 
- Selected project is now updated with new code and files. See How-tos for a complete list of generated files. 
Snippet from dataengine.h and dataengine.cpp:
class DataEngine : public DataEngineBase
{
    Q_OBJECT
    // Generated Signal MetaProperties
    Q_PROPERTY (IntConsumerSignal* engineRPM READ engineRPM CONSTANT)
    Q_PROPERTY (FloatConsumerSignal* oilPressure READ oilPressure CONSTANT)
    Q_PROPERTY (BoolProducerSignal* stopEngine READ stopEngine CONSTANT)
DataEngine::DataEngine() {
    // Define necessary signal properties for dataengine link initiation
    m_engineRPM = new IntConsumerSignal(false, false, 0);
    SIGNALTYPEDEF engineRPMDef;
    engineRPMDef.dataType = DATATYPE_INT;
    engineRPMDef.qtTypeName = "int";
    engineRPMDef.signalType = kSignalTypeConsumer;
    engineRPMDef.persistent = false;
    engineRPMDef.signal = m_engineRPM;
    m_signalTypeDefs["engineRPM"] = engineRPMDef;
Display signal value in QML¶
- Open - main.qmlwith the editor
- Locate - // add your GUI code below this line
- Add the following to display engineRPM and oilPressure signals in a Text component: - Text { id: engineRPM color: "white" text: dataEngine.engineRPM.value } Text { id: oilPressure color: "white" anchors.top: engineRPM.bottom text: dataEngine.oilPressure.value } 
- Compile and run the application. 
- Two text elements are shown and display “0” (no value is received yet). 
- Stop the application. 
Set a signal value from QML¶
- Add the following snippet beneath the code added in the previous section: - Rectangle { id: stopEngine width: 220; height: 60 anchors.top: oilPressure.bottom color: buttonMouseArea.pressed ? Qt.darker("grey", 1.5) : "grey" Text { anchors.centerIn: parent text: "Stop engine request" } MouseArea { id: buttonMouseArea anchors.fill: parent onPressed: dataEngine.stopEngine.value = true onReleased: dataEngine.stopEngine.value = false } } 
- Compile and run the application again. 
- The signal stopEngine is set to - truewhen the button is pressed and- falsewhen released. Assigned value is then sent to Data Engine to be consumed by another client.
- Stop the application