user7997307
user7997307

Reputation:

How can i build my class without conflict between QSqlTableModel and Q_OBJECT?

I'm trying to build next code, but compiler says:

"sqltablemodel.h:12: error: undefined reference to `vtable for SqlTableModel'"

I understand that the QSqlTableModel already has Q_OBJECT before.

But after removing this macro, I can't call my function from QML.

The debugger says that: ajax is not a function.

How can i build my class without conflict between inheritance & macros?

 //sqltablemodel.h
class SqlTableModel : public QSqlTableModel {
       Q_OBJECT
    public:    
       Q_INVOKABLE void ajax(){
           qDebug() << "123";
       }
    }

    //main.cpp
     SqlTableModel *sqlTableModel =  new SqlTableModel();
        context->setContextProperty("sqlTableModel", sqlTableModel);

Upvotes: 1

Views: 87

Answers (1)

user7997307
user7997307

Reputation:

I found a solution, When using Qt Creator:

Build → Run qmake

Build → Rebuild All

Upvotes: 1

Related Questions