Results 1 to 2 of 2

Thread: Passing the object from QML to CPP file?

  1. #1
    Join Date
    Jul 2016
    Posts
    53
    Thanks
    13
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Passing the object from QML to CPP file?

    Hi,
    I am developing an app.
    Query:
    How to pass the object from QML to CPP file, what will be object type in QT?

    Code:
    Login.QML
    Qt Code:
    1. function metPassObject()
    2. {
    3.  
    4. var myCar = new Object();
    5. myCar.make = "Ford";
    6. myCar.model = "Mustang"
    7. myCar.year = 1969;
    8.  
    9. objQtCPPSearchVOne.metPassObject(myCar);
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 
    .H file:
    Qt Code:
    1. Q_INVOKABLE void metPassObject (type parameter)- what will be the parameter type?
    To copy to clipboard, switch view to plain text mode 
    .CPP file:
    Qt Code:
    1. void metPassObject(type parameter)
    2. {
    3. //How to access the object?
    4. }
    To copy to clipboard, switch view to plain text mode 

    Thanks is Advance.
    Last edited by anda_skoa; 29th July 2016 at 18:05. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Passing the object from QML to CPP file?

    My guess would be QJSValue

    Qt Code:
    1. void metPassObject(const QJSValue &value)
    2. {
    3. QString make = value.property("make");
    4. }
    To copy to clipboard, switch view to plain text mode 

    But there could be other ways of achieving your actual goal.

    E.g. is this function intended to be called with different objects from different parts of the QML?

    Cheers,
    _

Similar Threads

  1. passing object to plugin
    By folibis in forum Qt Programming
    Replies: 3
    Last Post: 17th November 2011, 23:22
  2. Passing an object from one form to the other.
    By cbarmpar in forum Qt Programming
    Replies: 10
    Last Post: 3rd September 2008, 15:12
  3. passing an object
    By mickey in forum General Programming
    Replies: 3
    Last Post: 16th January 2008, 11:27
  4. Passing Object to dll
    By ankurjain in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2006, 10:50
  5. passing a QPainter object to widgets
    By vratojr in forum Qt Programming
    Replies: 9
    Last Post: 11th January 2006, 16:27

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.