Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-66822

Reference Error when looking up global context property

    XMLWordPrintable

Details

    • 3339bf866a68ba129e88fd7d27a2abbea0d1c6ba

    Description

      The lowenergyscanner example in QtBluetooth (https://doc-snapshots.qt.io/qt5-5.11/qtbluetooth-lowenergyscanner-example.html) uses a global context property:

      Device d;
      QQuickView *view = new QQuickView;
      view->rootContext()->setContextProperty("device", &d);
      

      During the execution of the example the QML engine returns a ReferenceError:

      qrc:/assets/Services.qml:120: ReferenceError: device is not defined

      The offending code line is triggered by the following code section:

      MouseArea {
          anchors.fill: parent
          onClicked: {
               pageLoader.source = "Characteristics.qml"; //Line 1
               device.connectToService(modelData.serviceUuid); //Line 2
          }
      }
      

      If Line1 and Line2 are swapped the reference error disappears. To reach this point of the example execution the following steps have to be taken:

      1. start lowenergyscanner
      2. click on "Search" (and wait until search complete)
      3. click on a BTLE device that you can connect to (and wait until service discovery is done)
      4. click on a service in the list

      The last click triggers the above connectToService() call.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              erikv Erik Verbruggen
              ablasche Alex Blasche
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes