Results 1 to 4 of 4

Thread: Using QSA: A very basic question

  1. #1
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Using QSA: A very basic question

    Hi!

    I want to make my Qt4.1 application scriptable, but am having trouble. My app has something like below: -
    Qt Code:
    1. -
    2. Object A
    3. / \
    4. Object AA Object AB
    5. / \
    6. Object AAA Object AAB
    To copy to clipboard, switch view to plain text mode 
    i.e 'Object A' has two members 'Object AA' & 'Object AB' and 'Object AA' has two more members 'Object AAA' & 'Object AAB'.

    I want all of the above objects accessible from script. For this QSA doc says:

    By passing an object to the scripting engine (using QSInterpreter::addTransientObject() or QSProject::addObject()), this object and all its signals, slots, properties, and child objects are made available to scripts
    Does it means the following code alone would expose all objects to script:-
    Qt Code:
    1. //Constructor of object A
    2. setObjectName("ObjectA");
    3. //Initialise all objects
    4. .
    5. .
    6. .
    7. .
    8. qsProject = new QSProject(this);
    9. qsProject->addObject(this);
    To copy to clipboard, switch view to plain text mode 

    Upon execution (While setting any property of 'ObjectAA') my app says 'ObjectAA' is undefined. This applies to all objects except 'ObjectA'.
    I have also tried adding all objects to the projects but result is same.

    Am i missing something? Please guide me.

    Thanks in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: Using QSA: A very basic question

    I think "child" doesn't mean a member variable but a child in a QObject-way: You have to pass ObjectA as parent to the constructor of ObjectAA to make AA become a child of A.
    It's nice to be important but it's more important to be nice.

  3. #3
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Using QSA: A very basic question

    Quote Originally Posted by axeljaeger
    I think "child" doesn't mean a member variable but a child in a QObject-way: You have to pass ObjectA as parent to the constructor of ObjectAA to make AA become a child of A.
    I am already doing that.

    I've attached copy of a trial app which i use for testing behaviour of QSA. You can try to look for loop-holes in the code. Doing only make will compile it. Upon executing it, you will find an editor widget which is used for executing script code. It is fairly easy.
    Attached Files Attached Files

  4. #4
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Using QSA: A very basic question

    For those who are too lazy to look into attachment, here is code present in the constructor of base object:
    Qt Code:
    1. setObjectName("trial");
    2. editor = 0;
    3.  
    4. qsProject = new QSProject(this);
    5.  
    6. m_pButton1 = new QPushButton("First", this);
    7. m_pButton2 = new QPushButton("Second", this);
    8. m_pButton2->move(20, 0);
    9. m_pButton1->setObjectName("button");
    10. m_pButton2->setObjectName("buttons");
    11.  
    12.  
    13. widget = new MyWidget(this, qsProject);
    14. widget->setObjectName("container_");
    15. widget->resize(50, 50);
    16. widget->move(50, 50);
    17.  
    18. m_pLabel1 = new MyLabel(this);
    19. m_pLabel1->setText("Hello World!");
    20. m_pLabel1->move(100, 100);
    21.  
    22. m_pLabel2 = new MyLabel(this);
    23. m_pLabel2->setText("Are You Listning?");
    24. m_pLabel2->move(100, 105);
    25.  
    26. resize( 200, 200);
    27.  
    28. // qsProject->addObject(m_pButton1);
    29. // qsProject->addObject(m_pButton2);
    30. // qsProject->addObject(widget);
    31. qsProject->addObject(this);
    32.  
    33. editor = new ScriptEditor( qsProject );
    34. editor->show();
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Basic QtScript question
    By jimboqt in forum Newbie
    Replies: 0
    Last Post: 23rd September 2008, 15:09
  2. Basic question on QComboBox
    By Raccoon29 in forum Newbie
    Replies: 2
    Last Post: 9th May 2008, 17:41
  3. Replies: 2
    Last Post: 21st February 2008, 23:35
  4. Replies: 5
    Last Post: 4th August 2006, 11:12
  5. Basic question on new and delete
    By jcr in forum General Programming
    Replies: 25
    Last Post: 14th February 2006, 16:09

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.