Dialog Settings window not loading variables.

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
kdwoll
Junior Member
Posts: 12
Joined: Wed Oct 26, 2022 12:51 pm

Dialog Settings window not loading variables.

Post by kdwoll » Thu Nov 14, 2024 5:24 pm

Option settings window. I have a custom program that insert points into a new layer on the existing drawing.

Program Layout
Screenshot 2024-11-14 100528.png
Screenshot 2024-11-14 100528.png (6.4 KiB) Viewed 53145 times

Main program code.

Code: Select all

AllPoints = undefined;
ZeroPoint = new RVector(0,0);
Corner1 = undefined;Corner2 = undefined;Corner4 = undefined;Corner5 = undefined;
Corner7 = undefined;Corner8 = undefined;var DrawOrder = 0;
var U4width = 0;var U4first = 0;var U4space = 0;var U6width = 0;var U6first = 0;var U6second = 0;var U6space  = 0;var U6offset = 0;
var U8width = 0;var U8first = 0;var U8second = 0;var U8third = 0;var U8space = 0;var U8offset = 0;var U8offset2 = 0;
Screenshot 2024-11-14 100418.png
Screenshot 2024-11-14 100418.png (35.6 KiB) Viewed 53145 times
Options Dialog code.

Code: Select all

// Include base class definition:
include("../nTruss.js");
 
// Constructor calls base class constructor:
function nTrussOptions(guiAction) {
    nTruss.call(this, guiAction);
}
 
// Derive class nTrussOptions from class nTruss:
nTrussOptions.prototype = new nTruss();
nTrussOptions.includeBasePath = includeBasePath;

 
nTrussOptions.prototype.beginEvent = function() {
    nTruss.prototype.beginEvent.call(this);

    // Create the dialog from the .ui file using the helper function WidgetFactory.createWidget().
    var dialog = WidgetFactory.createWidget(nTrussOptions.includeBasePath,"nTrussOptions.ui");

    // Restore the previous user data or display default values as set in Qt Designer:
    WidgetFactory.restoreState(dialog);
 
		// Display and execute the dialog:
		if (!dialog.exec()) {
			dialog.destroy();
			EAction.activateMainWindow();
			// User hit cancel:
			this.terminate();
			return;
		}
		
		    // User hit OK. Store the new user input:
    WidgetFactory.saveState(dialog);
    var widgets = getWidgets(dialog);
	

      nTruss.U6width = widgets["x6width"].text;
      nTruss.U6first = widgets["x6first"].text;
      nTruss.U6second = widgets["x6second"].text;
      nTruss.U6space = widgets["x6space"].text;
      nTruss.U6offset = widgets["x6offset"].text;
      nTruss.U8width = widgets["x8width"].text;
      nTruss.U8first = widgets["x8first"].text;
      nTruss.U8second = widgets["x8second"].text;
      nTruss.U8third = widgets["x8third"].text;
      nTruss.U8space = widgets["x8space"].text;
      nTruss.U8offset = widgets["x8offset"].text;
      nTruss.U8offset2 = widgets["x8offset2"].text;
      nTruss.U4width = widgets["x4width"].text;
      nTruss.U4first = widgets["x4first"].text;
      nTruss.U4space = widgets["x4space"].text;	
		
    dialog.destroy();
    EAction.activateMainWindow();
    this.terminate();
};
the problem is after I open the close this dialog box, all my other tools don't work.... Does the dialog window destroy something when it closes and goes back to main window? Or what else could be the issue?

This is the error that is generated. If anyone is interested, I can send you the complete project to test.
This does not happed if I don't open the dialog box.
Screenshot 2024-11-14 101423.png
Screenshot 2024-11-14 101423.png (125.45 KiB) Viewed 53145 times

User avatar
andrew
Site Admin
Posts: 8774
Joined: Fri Mar 30, 2007 6:07 am

Re: Dialog Settings window not loading variables.

Post by andrew » Thu Nov 14, 2024 5:43 pm

In the debugger that pops up, you can inspect the value of these variables by typing their name and pressing enter.

I would start by looking at the value of these variables:

Code: Select all

nTruss.corner4.x
nTruss.U6space
nTruss.corner4.y
c1
You can check if these are numbers using for example typeof(c1). I suspect that at least one of them might be a string or some other type.

CVH
Premier Member
Posts: 4920
Joined: Wed Sep 27, 2017 4:17 pm

Re: Dialog Settings window not loading variables.

Post by CVH » Fri Nov 15, 2024 1:03 am

Hi,

After the user hit OK you store text ... Strings:

Code: Select all

      nTruss.U6width = widgets["x6width"].text;
      nTruss.U6first = widgets["x6first"].text;
      nTruss.U6second = widgets["x6second"].text;
      nTruss.U6space = widgets["x6space"].text;
      nTruss.U6offset = widgets["x6offset"].text;
      ....
      
Your best option is to use input widgets based on RMathLineEdit and retrieve the value.
Otherwise convert the text to a number with:

Code: Select all

nTruss.U6first = parseFloat(widgets["x6first"].text);
...
Another option is to multiply it with 1.0 because then a text is first converted to a value if possible.

In the end you still have to verify if what was given is indeed a number value to be utterly sure.

Regards,
CVH

kdwoll
Junior Member
Posts: 12
Joined: Wed Oct 26, 2022 12:51 pm

Re: Dialog Settings window not loading variables.

Post by kdwoll » Fri Nov 15, 2024 3:34 am

Thank you so much. parseFloat worked.

Kevin

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”