Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to use QDeclarativeExtensionPlugin Items
Forum Updated to NodeBB v4.3 + New Features

How to use QDeclarativeExtensionPlugin Items

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 3 Posters 4.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    syrianzoro
    wrote on last edited by
    #1

    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

    Qt is the future

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vsorokin
      wrote on last edited by
      #2

      Did you read "Writing QML extensions with C++":http://doc.qt.nokia.com/4.7-snapshot/qml-extending-tutorial-index.html already?

      --
      Vasiliy

      1 Reply Last reply
      0
      • S Offline
        S Offline
        syrianzoro
        wrote on last edited by
        #3

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

        Qt is the future

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          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?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            syrianzoro
            wrote on last edited by
            #5

            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

            Qt is the future

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                syrianzoro
                wrote on last edited by
                #7

                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_OBJECT
                Q_PROPERTY(QSqlQueryModel *model READ model WRITE setModel)

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

                    setWidget(view);
                
                }
                

                void setModel(QSqlQueryModel *inModel)
                {
                m_model = inModel;
                }

                QSqlQueryModel *model()
                {
                return m_model;
                }
                private:
                QTableView *view;
                QSqlQueryModel *m_model;

                };

                class QWidgetsPlugin : public QDeclarativeExtensionPlugin
                {
                Q_OBJECT
                public:
                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
                
                MyView{
                
                }
                

                }
                @

                Qt is the future

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved