How to use QDeclarativeExtensionPlugin Items

  • Hello, could any one please tell me how to use the c++ Items which registered using QDeclarativeExtensionPlugin within c++, for instance if you register a tableWidget , it will shown and work properly but how you can populate it with data using any kind of models

  • Did you read "Writing QML extensions with C++": already?

  • Yes I did, but I can't register any kind of existing models, I have worked for long time but in vain

  • So, what are you trying to register exactly? A model or a view? Your first post seems to suggest a view, while your second post suggests a model. Could you clarify what you want to achieve please?

  • both classes ... I have registered a subclass of view and Qtablewidget but I don't know the way in which I can populate them with data

  • I don't think there is a way yet. AFAIK, the model interface used in Quick is still private API. There is an adaptor that makes it possible to use a QAbstractItemModel (-derived) class as such a model, but the other way around: using a QML-model in a QAbstractItemView is not supported.

    Note that you using a QTableWidget derived class doesn't help here either. The *widget classes are not mend to be used with external models, but only with their own internal one. If you want to use external models, use a QTableView derived class instead.

  • the following code works normally but I couldn't assign the model to the view using setproperty method

    @#include <QtDeclarative/QDeclarativeExtensionPlugin>
    #include <QtDeclarative/qdeclarative.h>
    #include <QtGui/QGraphicsProxyWidget>
    #include <QTableview>
    #include <QSqlqueryModel>
    #include <QDebug>

    class MyView : public QGraphicsProxyWidget
    Q_PROPERTY(QSqlQueryModel *model READ model WRITE setModel)

    MyView(QGraphicsItem* parent = 0)
    : QGraphicsProxyWidget(parent),view(new QTableView()),m_model(new QSqlQueryModel())


    void setModel(QSqlQueryModel *inModel)
    m_model = inModel;

    QSqlQueryModel *model()
    return m_model;
    QTableView *view;
    QSqlQueryModel *m_model;


    class QWidgetsPlugin : public QDeclarativeExtensionPlugin
    void registerTypes(const char *uri)
    qmlRegisterType<MyView>(uri, 1, 0, "MyView");

    #include "qWidgets.moc"

    Q_EXPORT_PLUGIN2(qmlqwidgetsplugin, QWidgetsPlugin);@

    this is the qml file

    @import QtQuick 1.0
    import "QWidgets" 1.0

    Rectangle {
    id: window

    property int margin: 30
    width: 640; height: 480
    color: palette.window


Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.