A little confused by signals & slots and passing values
privatepixels99
Posts: 36
Hi All,
I'm trying to get the value of an inputted value off a widget in a *.ui file, how do i do that?
Here's my code:
var ui_root; function cb_entryBox() { //How do we get the entry box value?"); } function ui_setup() { ui_root = new DzDialog(); var ui_loader = new DzUiLoader(); var widget = ui_loader.load("/some/path/test.ui", ui_root); var entryBox = widget.findChildOfWidget("lineEdit"); connect(entryBox, "returnPressed()", cb_entryBox); } ui_setup(); ui_root.exec();
Any pointers would be much appreciated (pun intended)
Comments
With DzLineEdit.text property you can get or set current value.
With Signals like textChanged or textEdited you get notified when DzLineEdit.text changes like when user is typing text.
http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/lineedit_dz#a_1ad210cd99141c8ad86b95c34688f37d91
You may already have seen this http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/language_reference/signals_slots/start
The syntax you are using here, "Signal to Function Connections" - http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/language_reference/signals_slots/start#signal_to_function_connections, is deprecated. There is a lot of information in http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/language_reference/signals_slots/start#connecting that explains how to connect methods to signals, including using methods that will be compatible with future versions of DS.
The syntax that provides access to the object that emits the signal, as 'this' within the slot being invoked (that is, defining a new object), is described in "Signal to Member Function Connections" (http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/language_reference/signals_slots/start#signal_to_member_function_connections).
The global syntax is the safest, the most portable, and has the least amount of overhead.
Thanks for the information, Richard. Clearly, there are more advantages in using scriptConnect.
Thank you both for your reactions - much appreciated :)
Richard - yes, I read the signal & slots page a good few times. After a while it sunk in :)
jag11 - thanks for your example. I had to modify
to
for it to work in my own little snipped of code though.
Then I went back to have a look at the signal definitions textChanged and textEdited which you suggested, and found the the missing link to my understanding of it all, It seems that returnPressed simply fires when a return is pressed but no values are passed. The text* signals do what I was looking for: they provide a parameter that holds the relevant text. It seems you're supposed to use the text* signals to keep track of the user's text entry and then use returnPressed just to keep track of a return being pressed.
I guess it's all my (very) bad for not reading things all the way through and I apologise for possibly wasting everybody's time somewhat.
oops.... i modified it to something entryBox.textChanged.connect of course.
I'll stop typing now, the world will be a better place for it.
i tried this:
var oLabelZ = new DzLabel( oVertBox );
oLabelZ.text = "Degree for side:"; // sText;
var oEditLineZ = new DzLineEdit ( oVertBox );
var nValZ = oEditLineZ.value;
print ("Z = " + nValZ);
and this:
...
var nValZ = oEditLineZ.text;
print ("Z = " + nValZ);
neither value nor text contains a value after running the whole script.
how can i get the value of the DZLineEdit?
What kind of value is the value that DZLineEdit gives back?
object, string or number?
text should be the one you want, as far as I know - http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/lineedit_dz#a_1a3d39cc5a71db46029fdbdb1183d46e98 - it is a string.
thanks
i already tried:
var nValZ = oEditLineZ.text;
print ("Z = " + nValZ);
but there was no outpint in the print although i added a value in the box.