PDA

View Full Version : Get pointer to class written in the script



Jonny174
24th July 2013, 11:37
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?



function tr(s)
{
return s;
}

function Trace( parent )
{
QGraphicsItem.call( this, parent );

this.setData( 0, 1000 );
this.setData( 1, 0 );
this.setData( 2, tr("След на нижней части чашки затвора") );
this.setFlag( QGraphicsItem.ItemIsSelectable );
this.normalPen = new QPen( new QColor( 0, 0, 0, 255 ), 2 );
this.selectedPen = new QPen( new QColor( 0, 0, 255, 150 ), 2 );

Qt.Scene.addItem( this );
}

Trace.prototype = new QGraphicsItem();

Trace.prototype.boundingRect = function()
{
return new QRectF( 0, 0, 50, 25 );
}

Trace.prototype.paint = function( painter, styleOptionGraphicsItem, widget )
{
if (this.isSelected())
painter.setPen( this.selectedPen );
else
painter.setPen( this.normalPen );

painter.drawArc( 0, 0, 50, 50, 2750, -2600 );
}

Trace.prototype.type = function()
{
return UserType + 1;
}

Trace.prototype.mouseMove = function( angle, x, y )
{
if (this.isSelected())
this.setRotation( -angle - 90 );
}

function addTrace()
{
var z = new Trace( Qt.Scene );
z.setPos( 275, 525 );
z.setTransformOriginPoint( z.mapFromParent( 300, 460 ) );
}

function getInfo()
{
return tr("След на нижней части чашки затвора");
}

function getData()
{
return 0;
}


Thanks!

wysota
24th July 2013, 15:56
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.