Unsolved TypeError: Property "..."of object "..."(0x1431f8e9420) is not a function. Couldn't find anything online which matched my case, any ideas?
-
main.cpp
#include "OntarioMaps.h" #include "ArcGISRuntimeEnvironment.h" #include "MapQuickView.h" #include <QDir> #include <QGuiApplication> #include <QQmlApplicationEngine> //------------------------------------------------------------------------------ using namespace Esri::ArcGISRuntime; int main(int argc, char *argv[]) { QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); // Register the map view for QML qmlRegisterType<MapQuickView>("Esri.OntarioMaps", 1, 0, "MapView"); qmlRegisterUncreatableType<QAbstractListModel>("Esri.OntarioMaps", 1, 0, "AbstractListModel", "AbstractListModel is uncreateable"); // Register the OntarioMaps (QQuickItem) for QML qmlRegisterType<OntarioMaps>("Esri.OntarioMaps", 1, 0, "OntarioMaps"); // Initialize application view QQmlApplicationEngine engine; // Add the import Path engine.addImportPath(QDir(QCoreApplication::applicationDirPath()).filePath("qml")); #ifdef ARCGIS_TOOLKIT_IMPORT_PATH_2 engine.addImportPath(ARCGIS_TOOLKIT_IMPORT_PATH_2); #endif // Set the source engine.load(QUrl("qrc:/qml/main.qml")); return app.exec(); }
OntarioMaps.h
... class OntarioMaps : public QQuickItem { Q_OBJECT Q_PROPERTY(Esri::ArcGISRuntime::MapQuickView* mapView READ mapView WRITE setMapView NOTIFY mapViewChanged) Q_PROPERTY(QAbstractListModel* suggestions READ suggestions NOTIFY suggestionsChanged) public: explicit OntarioMaps(QQuickItem* parent = nullptr); ~OntarioMaps() override; void componentComplete() override; Q_INVOKABLE void geoCode(const QString& query); Q_INVOKABLE void clearGraphics(); Q_INVOKABLE void setSuggestions(const QString& text); signals: void mapViewChanged(); void suggestionsChanged(); void hideSuggestionView(); ... };
OntarioMaps.cpp
... void OntarioMaps::geoCode(const QString& query) { SuggestParameters suggestParams; QStringList categories; categories << "Address" << "POI" << "Populated Place"; suggestParams.setCategories(categories); suggestParams.setMaxResults(5); m_locatorTask->suggestions()->setSuggestParameters(suggestParams); m_locatorTask->geocodeWithParameters(query, m_geocodeParams); } ...
qml
... Column { id: column width: 200 height: 400 TextField{ id: textField width: 285 height: 34 placeholderText: "Type in an address" font.pixelSize: 12 onTextChanged: { if (text.length > 0 && suggestView) { suggestView.visible = true; } model.setSuggestions(text); } } ListView { id: suggestView width: textField.width height: 195 model: model.suggestions visible: false clip: true delegate: Component { Rectangle { id: rect width: textField.width height: 34 color: "#f7f8fa" Text { anchors { verticalCenter: parent.verticalCenter leftMargin: 5 rightMargin: 5 } font { weight: Font.Black pixelSize: 16 } width: textField.width text: label elide: Text.ElideRight leftPadding: 5 color: "black" } MouseArea { anchors.fill: parent onClicked: { textField.text = label; suggestView.visible = false; model.geoCode(label); Qt.inputMethod.hide(); } } } } } } OntarioMaps { id: model mapView: view }
The exact error I get is : qrc:/qml/OntarioMapsForm.qml:112: TypeError: Property 'geoCode' of object QQmlDMAbstractItemModelData(0x1b06e4c0e00) is not a function
I tried my best to only include important parts so "..." is where other code would go. I have geoCode() as invokable so I'm not sure where the issue lies. Thanks for your help! Also the geoCode() call is at the end of QML and model.setSuggestions(text) works.
-
@CaptainJuice you have instantiated your
OntarioMaps
with the namemodel
. Try renaming it & obviously update anywhere you reference it. I think when you try to access it in your delegate it is being hidden by themodel
property of the delegate. -
@Bob64 Thankyou! It works now!