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. Qml + c++
Forum Updated to NodeBB v4.3 + New Features

Qml + c++

Scheduled Pinned Locked Moved QML and Qt Quick
10 Posts 3 Posters 8.9k 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.
  • niqtN Offline
    niqtN Offline
    niqt
    wrote on last edited by
    #1

    Hi
    i run with success this "http://doc.qt.nokia.com/4.7/qtbinding.html#calling-c-methods-from-qml":http://doc.qt.nokia.com/4.7/qtbinding.html#calling-c-methods-from-qml ,but when in run my application (my
    c++ class inherits from QSqlRelationalTableModel within Q_INVOCABLE fake funciton), i have this error:

    "Bar.qml:50 TypeError: Result of expressionon 'modelListItems.fake [undefined] is not a function"

    what's wrong?

    [edit: fixed link / chetankjain]

    1 Reply Last reply
    0
    • A Offline
      A Offline
      anselmolsm
      wrote on last edited by
      #2
      • Q_INVOKABLE, not Q_INVOCABLE
      • modelListItems.fake() , not modelListItems.fake

      Anselmo L. S. Melo (anselmolsm)

      1 Reply Last reply
      0
      • niqtN Offline
        niqtN Offline
        niqt
        wrote on last edited by
        #3

        I have Q_INVOKABLE and modelListItems.fake() in my code.

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

          [quote author="nicola1" date="1285600625"]I have Q_INVOKABLE and modelListItems.fake() in my code.[/quote]

          So, help us help you... more information needed.

          Anselmo L. S. Melo (anselmolsm)

          1 Reply Last reply
          0
          • niqtN Offline
            niqtN Offline
            niqt
            wrote on last edited by
            #5

            main.qml
            @
            import Qt 4.7
            import "content"

            Rectangle {
            width: 400
            height: 240
            function showListItems() {
            list.visible= false;
            listItems.visible = true;

                }
            function newList() {
                modelListItems.clear();
            
                ;
            }
            
            List {
                id: list
            }
            ListItems {
                id: listItems
                visible: false
            }
            Bar {
                onClickItems: showListItems();
                onClickNewList: modelListItems.fake();
            }
            

            }
            @

            main.cpp
            @
            QDeclarativeContext *ctxt = view.rootContext();
            ctxt->setContextProperty("modelListItems", &model);

            view.setSource(QUrl::fromLocalFile("listview/Main.qml");
            

            @

            My model.h
            @
            Q_INVOKABLE void fake() const;
            @

            My model.cpp
            @
            void Mymodel::fake() const
            {

            qDebug() << "FAKE " << endl;
            

            }
            @

            [edit: highlight added / Denis Kormalev]

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DenisKormalev
              wrote on last edited by
              #6

              Is there Q_OBJECT define in Mymodel class declaration?

              I see that you use object in stack, not in heap. Maybe object is out of scope and deleted because of it and so it is not accessible from Qml?

              1 Reply Last reply
              0
              • A Offline
                A Offline
                anselmolsm
                wrote on last edited by
                #7

                [quote author="Denis Kormalev" date="1285604321"]Is there Q_OBJECT define in Mymodel class declaration?[/quote]

                Denis is correct.

                Q_INVOKABLE member functions are called via the meta-object system, so you must add Q_OBJECT in your class declaration, then moc can do its job =)

                Anselmo L. S. Melo (anselmolsm)

                1 Reply Last reply
                0
                • niqtN Offline
                  niqtN Offline
                  niqt
                  wrote on last edited by
                  #8

                  I added Q_OBJECT and now is working, Thanks. I should understand because i need Q_OBJECT when y class inherit from QSqlTableModel.

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    DenisKormalev
                    wrote on last edited by
                    #9

                    nicola1, Jus make it

                    @
                    class QLSqlTableModel : public QSqlRelationalTableModel
                    {
                    Q_OBJECT
                    QHash<int, QByteArray> roles;
                    public:
                    QLSqlTableModel(QObject *parent = 0);
                    QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const;
                    Q_INVOKABLE void fake() const;
                    };
                    @

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      anselmolsm
                      wrote on last edited by
                      #10

                      [quote author="nicola1" date="1285657479"]I added Q_OBJECT and now is working, Thanks. I should understand because i need Q_OBJECT when y class inherit from QSqlTableModel.

                      [/quote]

                      "http://doc.trolltech.com/4.7/qobject.html#Q_OBJECT":http://doc.trolltech.com/4.7/qobject.html#Q_OBJECT

                      Anselmo L. S. Melo (anselmolsm)

                      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