Results 1 to 1 of 1

Thread: How to get QScriptValue property changes

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Question How to get QScriptValue property changes

    I have program which use global properties in QScriptEngine.
    There is the class of variable used in script code:

    Qt Code:
    1. #ifndef VARIABLECONFIGURATION_H
    2. #define VARIABLECONFIGURATION_H
    3.  
    4. #include <QMetaType>
    5.  
    6. class VariableConfiguration : public QObject
    7. {
    8. Q_OBJECT
    9. private:
    10. int _value;
    11. public:
    12. explicit VariableConfiguration(QObject *parent = 0);
    13. public slots:
    14. void setValue(int value);
    15. int value() const;
    16. signals:
    17. void valueChanged(int value);
    18. };
    19.  
    20. Q_DECLARE_METATYPE(VariableConfiguration*)
    21.  
    22. #endif // VARIABLECONFIGURATION_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "VariableConfiguration.h"
    2.  
    3. VariableConfiguration::VariableConfiguration(QObject *parent) :
    4. QObject(parent), _value(0) {
    5. }
    6.  
    7. void VariableConfiguration::setValue(int value) {
    8. if (_value != value) {
    9. _value = value;
    10. emit valueChanged(_value);
    11. }
    12. }
    13.  
    14. int VariableConfiguration::value() const {
    15. return _value;
    16. }
    To copy to clipboard, switch view to plain text mode 

    In main code:

    Qt Code:
    1. _scriptEngine = new QScriptEngine(this);
    2. qScriptRegisterMetaType(_scriptEngine, toScriptValue, fromScriptValue);
    3.  
    4. VariableConfiguration* var = new VariableConfiguration(this);
    5. connect(var, SIGNAL(valueChanged(int)), this, SLOT(variableValueChanged(int)));
    6.  
    7. _scriptEngine->globalObject().setProperty("intVar", toScriptValue(_scriptEngine, var));
    To copy to clipboard, switch view to plain text mode 

    For example, I need to run script code:
    intVar = 10;
    How can I do that variable emit valueChanged signal when property value changed while script running?
    P.S. Now I can use my variable class as intVar.setValue(10); but need intVar = 10;

    Thank you.
    Last edited by enamored; 16th February 2012 at 06:53. Reason: updated contents

Similar Threads

  1. looking for SortRole property example
    By umen in forum Qt Programming
    Replies: 0
    Last Post: 4th July 2011, 13:11
  2. Getting object's property...
    By gilamran in forum Newbie
    Replies: 1
    Last Post: 18th February 2011, 17:07
  3. QTScript - getting the name of a QScriptValue
    By android_ in forum Qt Programming
    Replies: 7
    Last Post: 28th October 2009, 14:24
  4. QScriptValue with simple typedef types
    By JohannesMunk in forum Newbie
    Replies: 9
    Last Post: 14th May 2009, 15:07
  5. enum property
    By illuzioner in forum Qt Tools
    Replies: 10
    Last Post: 22nd August 2006, 21:47

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.