Results 1 to 3 of 3

Thread: C++ pointer to Qml - is this possible?!?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2015
    Location
    Poland
    Posts
    34
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Exclamation Re: C++ pointer to Qml - is this possible?!?

    You won't notice my mention about setContextProperty... So I am not satisfy with your answer.
    Correct answer is that: Yes this is possible in that way:
    In order to use pointers variable in Qml you will have to do following steps:
    1. Register your class in order to make it understandable to QVariant:
    qRegisterMetaType<QSqlQueryModel*>("QSqlQueryModel *");
    2. Register your class in Qml:
    qmlRegisterType<QSqlQueryModel>("com.shomething", 1, 0, "QSqlQueryModel");
    3. Create your variable:
    QmlTableModel* lModel2 = new QmlTableModel(this);
    4. Get object contains your QSqlQueryModel* property from QQmlApplicationEngine:
    QObject* lCallbackObject = findObject(lCallbackObjectName);
    5. Set property:
    lCallbackObject->setProperty("mModel", QVariant::fromValue(lModel2));

    Essential in this procedure is QVariant::fromValue - qVariantFromValue will not work.
    I didn't check whether the same works with function calls from C++ to Qml, but it should.
    Last edited by Szyk; 17th May 2017 at 18:49.

Similar Threads

  1. Replies: 3
    Last Post: 23rd May 2015, 13:57
  2. Replies: 1
    Last Post: 4th December 2010, 17:20
  3. this pointer
    By salmanmanekia in forum General Programming
    Replies: 3
    Last Post: 11th June 2010, 08:43
  4. Pointer to Pointer
    By ^NyAw^ in forum General Programming
    Replies: 5
    Last Post: 25th April 2009, 08:00
  5. pointer
    By mickey in forum General Programming
    Replies: 4
    Last Post: 1st September 2006, 00:42

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.