Results 1 to 8 of 8

Thread: Need help passing data to qml

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    Join Date
    Dec 2014
    Posts
    7
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Android

    Default Re: Need help passing data to qml

    hey thanks for the code but it still does not work. this is what i am using

    .cpp
    Qt Code:
    1. using namespace Ui;
    2. QQmlEngine engine;
    3. QQmlComponent component(&engine, "/home/user/projects-qt5/test_qml/MyItem.qml");
    4. QObject *object = component.create();
    5. QVariant returnedValue;
    6.  
    7. MyStruct s;
    8. s.i=12;
    9. s.name="Hello QML";
    10. QVariantMap map;
    11. map["i"] = s.i;
    12. map["name"] = s.name;
    13.  
    14. QVariant v = map;
    15. QMetaObject::invokeMethod(object, "myQmlFunction",
    16. Q_RETURN_ARG(QVariant, returnedValue),
    17. Q_ARG(QVariant,v));
    To copy to clipboard, switch view to plain text mode 
    .h
    Qt Code:
    1. namespace Ui {
    2. class Dialog;
    3. struct MyStruct {
    4. int i;
    5. QString name;
    6. };
    7. }
    8. ...
    9. Q_DECLARE_METATYPE(Ui::MyStruct)
    10. #endif // DIALOG_H
    To copy to clipboard, switch view to plain text mode 
    .qml
    Qt Code:
    1. import QtQuick 2.0
    2.  
    3. // MyItem.qml
    4.  
    5. Item {
    6.  
    7. function myQmlFunction(v) {
    8. console.log("Got message:",v.name)
    9. return "some return value"
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 
    app output
    qml: QML Got message: undefined
    QML function returned: "some return value"
    comp error is ()
    Last edited by anda_skoa; 22nd April 2015 at 15:19. Reason: missing [code] tags

Similar Threads

  1. passing data from forms
    By shreeram in forum Qt Programming
    Replies: 3
    Last Post: 17th March 2015, 15:37
  2. Passing data between QWizard and QWizardpages
    By Srstka in forum Qt Programming
    Replies: 1
    Last Post: 9th November 2014, 20:23
  3. Passing data to a QThread
    By lynchkp in forum Newbie
    Replies: 4
    Last Post: 10th March 2011, 22:02
  4. Passing data via signal/slot
    By gib in forum Qt Programming
    Replies: 4
    Last Post: 1st November 2010, 05:49
  5. passing data when closing a dialog
    By jimiq in forum Newbie
    Replies: 4
    Last Post: 4th November 2009, 16:48

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.