Results 1 to 6 of 6

Thread: Calling QML functions from C++

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2016
    Posts
    81
    Thanks
    31
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Calling QML functions from C++

    Thank you,
    I have this code in "MySerialPort" class:
    Qt Code:
    1. void MySerialPort::readData()
    2. {
    3. QByteArray data = serial->readAll();
    4. if(data[0]=='0') // For example
    5. Show qml dialog
    6. if(data[1]=='1') // For example
    7. disable GroupBox
    8.  
    9. ...
    10. ...
    11. }
    To copy to clipboard, switch view to plain text mode 

    How can I handled this code on the QML side?

  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: Calling QML functions from C++

    The usual way is to have a property on a C++ object that is exposed to QML.
    I think we've already discussed this before.

    In this case maybe an int or enum property.

    QML then reacts to changes of that property the usual way, e.g. via property bindings.

    Or you emit signals and handle these in QML, e.g. using a Connection element

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    neda (12th March 2016)

Similar Threads

  1. Replies: 2
    Last Post: 18th October 2012, 13:31
  2. Calling class functions from another function
    By prophet0 in forum General Programming
    Replies: 2
    Last Post: 2nd March 2012, 21:16
  3. ActiveQt not calling COM functions
    By daveg in forum Qt Programming
    Replies: 3
    Last Post: 11th October 2011, 09:45
  4. Replies: 5
    Last Post: 17th November 2010, 17:29
  5. Calling GUI functions from a DLL
    By inktomi in forum Qt Programming
    Replies: 0
    Last Post: 19th July 2010, 12:50

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.