Results 1 to 2 of 2

Thread: Get pointer to class written in the script

  1. #1
    Join Date
    Apr 2011
    Location
    Russia
    Posts
    85
    Thanks
    2
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Get pointer to class written in the script

    Hi all.
    I'm use qtscriptgenerator for make Qt classes in the scripts.
    I wrote a class Trace inherits of QGraphicsItem and add a new function Trace.prototype.mouseMove = function( angle, x, y ).

    How I can call this function from main programm?
    May I get a pointer to class Trace in the main programm?

    Qt Code:
    1. function tr(s)
    2. {
    3. return s;
    4. }
    5.  
    6. function Trace( parent )
    7. {
    8. QGraphicsItem.call( this, parent );
    9.  
    10. this.setData( 0, 1000 );
    11. this.setData( 1, 0 );
    12. this.setData( 2, tr("След на нижней части чашки затвора") );
    13. this.setFlag( QGraphicsItem.ItemIsSelectable );
    14. this.normalPen = new QPen( new QColor( 0, 0, 0, 255 ), 2 );
    15. this.selectedPen = new QPen( new QColor( 0, 0, 255, 150 ), 2 );
    16.  
    17. Qt.Scene.addItem( this );
    18. }
    19.  
    20. Trace.prototype = new QGraphicsItem();
    21.  
    22. Trace.prototype.boundingRect = function()
    23. {
    24. return new QRectF( 0, 0, 50, 25 );
    25. }
    26.  
    27. Trace.prototype.paint = function( painter, styleOptionGraphicsItem, widget )
    28. {
    29. if (this.isSelected())
    30. painter.setPen( this.selectedPen );
    31. else
    32. painter.setPen( this.normalPen );
    33.  
    34. painter.drawArc( 0, 0, 50, 50, 2750, -2600 );
    35. }
    36.  
    37. Trace.prototype.type = function()
    38. {
    39. return UserType + 1;
    40. }
    41.  
    42. Trace.prototype.mouseMove = function( angle, x, y )
    43. {
    44. if (this.isSelected())
    45. this.setRotation( -angle - 90 );
    46. }
    47.  
    48. function addTrace()
    49. {
    50. var z = new Trace( Qt.Scene );
    51. z.setPos( 275, 525 );
    52. z.setTransformOriginPoint( z.mapFromParent( 300, 460 ) );
    53. }
    54.  
    55. function getInfo()
    56. {
    57. return tr("След на нижней части чашки затвора");
    58. }
    59.  
    60. function getData()
    61. {
    62. return 0;
    63. }
    To copy to clipboard, switch view to plain text mode 

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Get pointer to class written in the script

    Quote Originally Posted by Jonny174 View Post
    May I get a pointer to class Trace in the main programm?
    Trace is not really a class but a function that returns an object. You can store this function in QScriptValue, call() it to receive the object (again a QScriptValue), then access the resulting object's "mouseMove" property and call that.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Jonny174 (25th July 2013)

Similar Threads

  1. Replies: 10
    Last Post: 7th January 2013, 11:15
  2. show object (scene) in widget in class class mainwindow
    By rimie23 in forum Qt Programming
    Replies: 8
    Last Post: 1st May 2012, 16:15
  3. Binding a class into Qt script engine
    By kaspi in forum Qt Programming
    Replies: 1
    Last Post: 5th December 2010, 07:54
  4. Can I include a script from script?
    By yycking in forum Qt Programming
    Replies: 1
    Last Post: 24th April 2009, 03:01
  5. Replies: 3
    Last Post: 27th December 2008, 19:34

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.