Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Basic qml label update with cpp



  • Hey guys,

    i have a pretty simple question but i dont find a solution:

    I want to update this qml component when the property ACSQmlTool.linkTool.isConnected changes:

    Label {
    	id:                      connectionLost
    	text:		         ACSQmlTool.linkTool.isConnected ? qsTr("Link connected!") : qsTr("Link disconnected")
    	font.pointSize:		 ScreenTools.defaultFontPointSize
    	font.family:		 ScreenTools.normalFontFamily
    	font.weight:		 Font.Normal
    	color:			 ACSQmlTool.linkTool.isConnected ? ACSPalette.lightblueLight : ACSPalette.orange
    	visible:		 ACSQmlTool.linkTool.isConnected
    }
    

    Unfortunately it doesn't change even if the property changes.



  • @MaxBec hi
    what is that ACSQmlTool ? how it is exposed to qml ?

    @MaxBec said in Basic qml label update with cpp:

    even if the property changes.

    how do you check that ?



  • LinkTool:

    class ACSLinkTool : public ACSAbstractTool
    {
    		Q_OBJECT
    
    	public:
    		ACSLinkTool(ACSApplication* app, ACSToolbox* toolbox);
    		~ACSLinkTool();
    
    		Q_PROPERTY(bool						isBluetoothAvailable		READ isBluetoothAvailable		CONSTANT)
    		Q_PROPERTY(ACSQmlListModel*				linkConfigurations			READ _qmlLinkConfigurations		NOTIFY linkConfigurationsChanged)
    		Q_PROPERTY(QStringList					linkTypeStrings			READ linkTypeStrings			CONSTANT)
    		Q_PROPERTY(QStringList					serialBaudRates			READ serialBaudRates			CONSTANT)
    		Q_PROPERTY(QStringList					serialPortStrings			READ serialPortStrings			NOTIFY commPortStringsChanged)
    		Q_PROPERTY(QStringList					serialPorts				READ serialPorts				NOTIFY commPortsChanged)
    		Q_PROPERTY(bool						isConnected				READ isConnected				NOTIFY isConnectedChanged)
    

    QmlTool:

    qmlRegisterSingletonType		<ACSQmlTool>				("ACSCpp.Qml",				1, 0, "ACSQmlTool",				qmlToolSingletonFactory);
    

    isConnected is directly changed in the code for debug purposes.



  • @MaxBec said in Basic qml label update with cpp:

    did you emit isConnectedChanged() signal when you write the new value?


Log in to reply