I want to pass variables from my C++ class to a function in my QML class so that the function can use them.
I am trying to use a signal and connection but it's not working.
Here's my relevant code:
main
...
qmlRegisterType<Client>("Client", 1, 0, "Client");
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/map.qml")));
...
cpp header
class Client : public QDialog
{
Q_OBJECT
public:
explicit Client(QWidget *parent = nullptr);
...
public slots:
void callDoAddMarker(float latitude, float longitude);
signals:
void doAddMarker(float latitude, float longitude);
cpp class
void Client::someFunction(UINT16 array[]) {
...
callDoAddMarker(latit, longit);
}
void Client::callDoAddMarker(float latitude, float longitude) {
emit doAddMarker(latitude, longitude);
}
and in QML
import Client 1.0
...
function addMarker(latitude, longitude) {
...
}
Client {
id: client
}
Connections {
target: client
onDoAddMarker: {addMarker(latitude, longitude)}
}
Can someone tell me what I'm doing wrong? Any help is greatly appreciated!
EDIT: Adding in my main to show how I register the cpp class with QML, not sure if this is correct.