Borrar filtros
Borrar filtros

some variables doesn't exist in handles after exiting callback function

2 visualizaciones (últimos 30 días)
Wenjie Wu
Wenjie Wu el 29 de Sept. de 2015
Comentada: Walter Roberson el 30 de Sept. de 2015
MATLAB 2015a
Q1:
For example, in a callback function of a text box (Note that: I made the function name different from the 'varName')
function uiVarName_Callback(hObject, eventdata, handles)
handles.varName = get(hObject,'String');% get varName
guidata(hObject,handles); % update gui handles
When the function exits, I cannot find varName in the handles(which I think is a master handle across the board).
In other callback functions, if I call handles.varName,
it says 'Reference to non-existent field'
Q2: How can I extract only the value of a textbox, for example, uiVarName. When I type uiVarName without a ;, then it returns as follow, which is not value in the ext box.
UIControl (uiVarName) with properties:
Style: 'edit'
String:
BackgroundColor: [0.9400 0.9400 0.9400]
Callback: @(hObject,eventdata)sharp_gui('uiMinPkWidth_Callback',hObject,eventdata,guidata(hObject))
Value:
Position: [0.0500 0.1163 0.1365 0.4419]
Units: 'normalized'

Respuestas (1)

Walter Roberson
Walter Roberson el 30 de Sept. de 2015
Q2: You appear to be using R2014b or later, so you can use
uiVarName.Value
Note that the Value of a uicontrol('Style','text') has not been assigned any meaning; see http://www.mathworks.com/help/matlab/ref/uicontrol-properties.html#property_value
If you are looking for the text that has been put in the text box then
uiVarName.String
Q1:
  • guidata(hObject,handles) would update the guidata (handles) structure associated with the figure that hObject belongs to. If you have multiple figures then that is not necessarily the same place that other handles references are getting the data from.
  • when you use guidata() to update the master "handles" structure, other routines will not observe the update until they request the current copy of the data. If you are using GUIDE then the update should show up the next time they are called, but if you have one callback routine call another callback routine that updates the handles then the first routine will not know.
  7 comentarios
Adam
Adam el 30 de Sept. de 2015
You can tell very quickly whether the function is even being called or not by either putting a disp( 'Something or other' ) statement in it and seeing if that appears in your command window or just putting a breakpoint in.
That seems like the key question. Your syntax with respect to handles looks fine, but if the function never gets called then that would be the simplest explanation why the field does not exist.
Walter Roberson
Walter Roberson el 30 de Sept. de 2015
But your handles.x is not an edit text box. Your edit text box is handles.uiVarName

Iniciar sesión para comentar.

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by