QML Serial: Multiple qml files using 1 serial port
Solved
QML and Qt Quick
-
I have a window consist of 2 Items (2 .qml files). One of those was connected with serial port. But I can't use that serial port for 2nd Item.
Item 1: Checking connection and "visible" Item 2
Item 2: Emit and Receiver data
I need a advise. Thanks very much -
Show us some code, it's hard to advise anything without it.
Sharing an object between files is definitely possible.
-
@sierdzio This my code: Sorry for delay and my PC don't have internet
main.qml:
import QtQuick 2.12 import QtQuick.Window 2.12 import QtQuick.Controls.Material 2.12 import Qt.labs.platform 1.0 import QtQuick.Controls 2.12 import QtQuick.Dialogs 1.2 as D2 import SerialPort 1.0 impot "." Window { readonly property int w_config: 320 readonly property int h_config: 240 readonly property int w_vcm: 1280 readonly property int h_vcm: 720 id: home width: w_config height: h_config visible: true Material.theme: Material.Dark Material.accent: Material.LightBlue SerialPort { id: serialPort } Item { id: config_page visible: true anchor.fill: parent ConFig { id: com_config } Connections { target: con_config onStartSignal: { config_page.visible = false vcm_page.visible = true console.log ("serial port in main.qml: "+ serialPort.getConnectionStatusSlot()) \\return: false ==> THIS IS MY PROBLEM home.width = w_vcm home.height = h_vcm home.x = screen.width/2 - w_vcm/2 home.y = screen.height/2 - h_vcm/2 } } } Item { id: vcm_page visible: false anchor.fill: parent VCM02{ id: vcm_02 } Connections { target: vcm_02 onHomeSig: { home.width = w_config home.height = h_config home.x = screen.width/2 - w_config/2 home.y = screen.height/2 - h_config/2 config_page.visible = true vcm_page.visible = false } } } }
ConFig.qml
import QtQuick 2.0 import QtQuick.Controls 2.12 import QtGraphicalEffects 1.0 import QtQuick.Dialogs 1.2 as D1 import SerialPort 1.0 Item { width: 320 height: 240 anchors.centerIn: parent signal startSignal() SerialPort { id: serialPort } Rectangle { anchors.fill: parent color: "#3d3d4c" ComboBox { id: comList width: parent.width/2 height: parent.height/6 anchors.top: parent.top anchors.horizontalCenter: parent.horizontalCenter anchors.margins: 100 font.pixelSize: 16 model: serialPort.PortName // add in serialport.h and serialport.cpp } Button { id: connectBtn onClicked: { \\check connecttion..if connection is OK enable startBtn } } Button { id: startBtn onClicked: { startSignal() console.log ("serial port in ConFig.qml: "+ serialPort.getConnectionStatusSlot()) \\return: true } } } }
VCM02.qml
import .... Item { \\I wanna use serial port in this form but serialPort.getConnectionStatusSlot() = false \\serialPort.getConnectionStatusSlot() function in serialport.h and .cpp }