I am doing a database operations in my project. I have a file 'dataBaseMaster',which has a function updateIntoTestResult(). I have created a dbMasterObject by setting context like this
qml->setContextProperty("dbMasterObject", dbMasterObject);
but when i try to call this updateIntoTestResult() method in my main.qml,i am getting an error like this
TypeError: Result of expression 'dbMasterObject.updateIntoTestResult' [undefined] is not a function
DatabaseMaster.hpp
class DatabaseMaster : public QObject
{
public:
Q_OBJECT
public:
void updateIntoTestResult(int id, int result);
};
DatabaseMaster.cpp
void DatabaseMaster::updateIntoTestResult(int id, int result) {
QSqlDatabase database = QSqlDatabase::database();
QSqlQuery query(database);
query.prepare("update "+TEST_RESULT_MASTER+" set "+RESULT+" = :"+RESULT+" where "+TEST_ID+"= :"+TEST_ID+";");
query.bindValue(":"+RESULT, result);
query.bindValue(":"+TEST_ID, id);
query.exec();
calling in main.qml
dbMasterObject.updateIntoTestResult(MICROPHONE_ID, TEST_STATE_PASS)
please help me out, why am i getting this error whereas i have declared that method correctly.
Thanks in advance..!!
updateIntoTestResult
is not known to qml system because it's not a slot or Q_INVOKABLE
.
Simple fix - insert Q_INVOKABLE
:
class DatabaseMaster : public QObject
{
public:
Q_OBJECT
public:
Q_INVOKABLE void updateIntoTestResult(int id, int result);
};