Results 1 to 5 of 5

Thread: Periodically access QML variable from C++

  1. #1
    Join Date
    Nov 2015
    Posts
    3
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Android Maemo/MeeGo

    Default Periodically access QML variable from C++

    Dear Qt Specialists!

    I would like to access, lets say every 10 millisecond, a certain QT-QML variable (I am not even sure if I am speaking the proper wording) from C++ and use that information to run some code in C++ to manipulate some external, not connect through the QML, platform.

    For example: imagine, QML provides a particular value from a certain sensor, which is continuously updating. I would like to periodically access this from C++ to move the mouse cursor in linux.

    Any suggestions? Thank you all.
    mekarim

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

    Default Re: Periodically access QML variable from C++

    - Create a QObject based class with a property of the type you want.
    - Create an instance of that class and set it as a context property on the QQmlEngine's root context
    - Write to that property in QML
    - React to the value change in the property's setter function or run a QTimer that reads the stored value

    Cheers,
    _

  3. #3
    Join Date
    Nov 2015
    Posts
    3
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Android Maemo/MeeGo

    Default Re: Periodically access QML variable from C++

    Dear Anda_skoa

    Thank you so much. I think I partially understand what you are saying.

    Do you mind sharing one example, please? A short one would suffice as well.

    Thank you again.
    Cheers

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Periodically access QML variable from C++

    A bit like this http://doc.qt.io/qt-5/qtqml-cppinteg...ntext-property

    They don't use a property but the principle is similar.

    Cheers,
    _

  5. #5
    Join Date
    Nov 2015
    Posts
    3
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Android Maemo/MeeGo

    Default Re: Periodically access QML variable from C++

    Thank you so much. I think this will do. I will check and update.

    Cheers

Similar Threads

  1. how can dialog access variable from parent MainWindow?
    By krezix in forum Qt Programming
    Replies: 5
    Last Post: 30th April 2012, 00:20
  2. Access Signal of Class Member Variable
    By starkid in forum Newbie
    Replies: 7
    Last Post: 19th October 2011, 00:19
  3. Access variable using its name as QString
    By homerun4711 in forum Newbie
    Replies: 3
    Last Post: 22nd December 2010, 09:11
  4. QtScript access variable from C++
    By bunjee in forum Qt Programming
    Replies: 2
    Last Post: 16th January 2009, 23:51
  5. main.cpp variable access question
    By MarkoSan in forum Qt Programming
    Replies: 10
    Last Post: 10th March 2008, 20: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.