Results 1 to 4 of 4

Thread: QtScript Binding problem with QWidget

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Jan 2006
    Posts
    132
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QtScript Binding problem with QWidget

    One difference to my working prototypes is the constructor. Translated to your class it would be:

    Qt Code:
    1. QScriptValue WidgetPrototype::construct(QScriptContext *ctx, QScriptEngine *eng)
    2. {
    3. if(ctx->argumentCount()==0)
    4. {
    5. // use newQObject; script ownership
    6. return eng->newQObject(new QWidget(), QScriptEngine::ScriptOwnership);
    7. }
    8.  
    9. return eng->undefinedValue();
    10. }
    To copy to clipboard, switch view to plain text mode 

    Other differences:

    Qt Code:
    1. // prototype object not on stack:
    2. WidgetPrototype* WidgetPrototypeObject = new WidgetPrototype();
    3.  
    4. // make it script owned:
    5. QScriptValue widgetProto = engine.newQObject(WidgetPrototypeObject, QScriptEngine::ScriptOwnership);
    6.  
    7. engine.setDefaultPrototype(qMetaTypeId<QWidget*>(), widgetProto);
    8. QScriptValue widgetCtor = engine.newFunction(WidgetPrototype::construct, widgetProto);
    9. engine.globalObject().setProperty("Widget", widgetCtor);
    To copy to clipboard, switch view to plain text mode 
    Last edited by seneca; 17th February 2009 at 08:35.

Similar Threads

  1. Problem with Size Policy of derived QWidget
    By eehmke in forum Qt Programming
    Replies: 6
    Last Post: 12th November 2008, 13:43
  2. QWidget Refresh Problem
    By MarkoSan in forum Qt Programming
    Replies: 2
    Last Post: 15th January 2008, 11:24
  3. QtScript Q_ENUM problem
    By oc2k1 in forum Qt Programming
    Replies: 0
    Last Post: 14th May 2007, 16:07
  4. QScrollArea problem positioning a QWidget inside
    By Spectator in forum Qt Programming
    Replies: 4
    Last Post: 20th February 2006, 22:59

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.