Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML Serial: Multiple qml files using 1 serial port
Forum Updated to NodeBB v4.3 + New Features

QML Serial: Multiple qml files using 1 serial port

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 361 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    taind
    wrote on last edited by taind
    #1

    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

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Show us some code, it's hard to advise anything without it.

      Sharing an object between files is definitely possible.

      (Z(:^

      T 1 Reply Last reply
      0
      • T Offline
        T Offline
        taind
        wrote on last edited by taind
        #3

        @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
        }
        
        1 Reply Last reply
        0
        • sierdzioS sierdzio

          Show us some code, it's hard to advise anything without it.

          Sharing an object between files is definitely possible.

          T Offline
          T Offline
          taind
          wrote on last edited by
          #4

          @sierdzio I found it...because I used Component "SerialPort" for each Item. So that created new Object . I try change qmlRegisterType -> QQmlComtext and it worked ...Thank you for your supporting. Have good day!!

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved