Running onClicked [solved]



  • Hi! I'm doing a Qt Quick aplication for android, and I have a BluetoothDiscoveryModel, but I want that the bluetoothDiscoveryModel starts running just when I clicked on button, but I can't do this.. someone can help me?

    here's the piece of code that I want to change. I want: onClicked: top.state = "begin" and btModel.running = true..

    Button {
            id: but
            text: qsTr("Entrar")
            anchors.centerIn: parent
            onClicked: top.state == "begin";
        }
    

    //////////////////////////////////////////searchBox///////////////////////////////////////////////////////////////////////

         Search {
                id: searchBox
                opacity: 0;
                anchors.centerIn:parent; 
           }
    
         BluetoothDiscoveryModel {
             id: btModel
             running : true
    
             discoveryMode: BluetoothDiscoveryModel.MinimalServiceDiscovery
             onRunningChanged : {
                 if (!btModel.running && top.state == "begin" && !serviceFound) {
                     searchBox.animationRunning = false;
                     searchBox.appendText("\nNenhuma bicicleta encontrada. \n\nPor favor\nreinicie a aplicação.")
                 }
             }
             onServiceDiscovered: {
                 if (serviceFound)
                    return
                 serviceFound = true
                 console.log("Found new service " + service.deviceAddress + " " + service.deviceName + " " + service.serviceName);
                 searchBox.appendText("\nA conectar...")
                 remoteDeviceName = service.deviceName
                 socket.setService(service)
             }
             //uuidFilter: "e8e10f95-1a70-4b27-9ccf-02010264e9c8"
             remoteAddress: "00:12:06:01:59:08"
         }
    

    thanks

    Edited: Please use ``` to post code blocks - p3c0


  • Moderators

    Hi @joanaguimas
    What is top ?



  • @p3c0

    It's just the Id that I create for the begin..

    // Item {

      property string remoteDeviceName: ""
      property bool serviceFound: false
    
    id: top
    visible: true
    width: 640
    height: 480
    

    (...)


  • Moderators

    @joanaguimas Ok. You can do this instead:

    onClicked: btModel.running = true
    


  • @p3c0 I just tried this one, but here, I put running: true, false or nothing?

    // BluetoothDiscoveryModel {

         id: btModel
    
         running : true
    
         discoveryMode: BluetoothDiscoveryModel.MinimalServiceDiscovery
         onRunningChanged : {
             if (!btModel.running && top.state == "begin" && !serviceFound) {
                 searchBox.animationRunning = false;
                 searchBox.appendText("\nNenhuma bicicleta encontrada. \n\nPor favor\nreinicie a aplicação.")
             }

  • Moderators

    @joanaguimas Put it false initially then onClicked set it to true.



  • @p3c0 It worked! I had already tried and it had failed, maybe there was something wrong, but now works well!

    thank you!


  • Moderators

    @joanaguimas Congratulations :) Happy Coding..


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.