Page 1 of 1

Exception

Posted: Wed Dec 04, 2013 6:09 pm
by sramp
Hello,
I'm coding my first trials with qcad scripting, but I'm encountering problems. I hope somebody can point me in the right direction.
I'm using qcad-pro with a MacOS 1.7.5.
As first trial I have added to the tutorial Menus and Tool Bars a new item called TestDialog.
TestDialog should simply display a dialog made with QtDesigner ( very simple dialog, few buttons and some labels).
MyAction command works fine, while my new command TestDialog, dies silently.
Starting qcad with the -enable-script-debugger I can se that I'm getting an exception :

Code: Select all

Uncaught exception at scripts/TestQCAD/TestDialog/TestDialog.js:8: RangeError: Maximum call stack size exceeded.
8	    TestDialog.prototype.beginEvent.call(this);
Following my TestDialog.js source code ... that's a lazy copy of PersistentWidgets without persistence.
include("../WidgetFactory.js");
include("../TestQCAD.js");
function TestDialog(guiAction) {
    TestQCAD.call(this, guiAction);
}
TestDialog.prototype = new TestQCAD();
TestDialog.prototype.beginEvent = function() {
    TestDialog.prototype.beginEvent.call(this);
    // Create the dialog from the .ui file using the helper
    // function WidgetFactory.createWidget().
     
    var dialog = WidgetFactory.createWidget("../TestQCAD/TestDialog","TestDialog.ui");
    
    // Display and execute the dialog:
    if (!dialog.exec()) {
    	
        // User hit cancel:
        this.terminate();
        return;
    }
     
    
    this.terminate();
};
TestDialog.init = function(basePath) {
    var action = new RGuiAction(qsTr("&Test Dialog"),
        RMainWindowQt.getMainWindow());
    action.setRequiresDocument(true);
    action.setScriptFile(basePath + "/TestDialog.js");
    action.setSortOrder(10);
    EAction.addGuiActionTo(action, TestQCAD, true, false, false);
};
BTW I've tried to run the PersistentWidgets starting qcad enabling xdata, but I get another exception :

Code: Select all

Uncaught exception at /Applications/QCAD-Pro.app/Contents/Resources/scripts/WidgetFactory.js:371: TypeError: Result of expression 'widget' [undefined] is not an object.
371	        };
Thanks in advance.
Kind Regards
sramp

Re: Exception

Posted: Wed Dec 04, 2013 6:22 pm
by andrew
sramp wrote:
TestDialog.prototype.beginEvent = function() {
    TestDialog.prototype.beginEvent.call(this);
    ...
}
The line TestDialog.prototype.beginEvent.call(this); calls the same function beginEvent recursively.

The idea of that line is to call the beginEvent function of the base class (in this case TestQCAD):
TestDialog.prototype.beginEvent = function() {
    TestQCAD.prototype.beginEvent.call(this);
    ...
}

Re: Exception

Posted: Wed Dec 04, 2013 7:14 pm
by sramp
Hi Andrew,
thanks for the prompt reply.
You're right, it's a stupid error of mine.
Sorry for the noise.
After fixing a bad path, everything works fine.