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

  1. Open Qt Creator.

  2. File > New file or Project....

  3. Select CrossControl Project and pick Qt Quick 2 Application.

  4. Follow the on-screen instructions to finalize the project creation:

    1. Display resolution: 800x480

    2. Kit: Desktop

Create signals for the application

  1. Open LinX Manager Data Engine from the mode selector (left side).

  2. Select the created project from the project selector drop-down menu.

  3. Create three signals by pressing the add button Add signal.

  4. 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

  1. From the projector selector, press “Save” for the changes to take effect.

  2. Verify that the project was updated by opening the General Messages tab (Alt+6):

    LinX Manager Data Engine: Project updated successfully.

  3. 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

  1. Open main.qml with the editor

  2. Locate // add your GUI code below this line

  3. 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
    }
    
  4. Compile and run the application.

  5. Two text elements are shown and display “0” (no value is received yet).

  6. Stop the application.

Set a signal value from QML

  1. 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
        }
    }
    
  2. Compile and run the application again.

  3. The signal stopEngine is set to true when the button is pressed and false when released. Assigned value is then sent to Data Engine to be consumed by another client.

  4. Stop the application