回调函数在gui中不知道句柄 [英] callback function in gui does not know handles
问题描述
我尝试在我的gui中实现一个后退功能更新等待。我将函数句柄传递到加载图像的函数。
function z_WaitBarUpdate(value,maxValue)
handles = guidata(handles.output); %< - 失败,因为句柄未知
如果ishandle(handles.waitbar.handle)
waitbar(value / maxValue,handles.waitbar.handle,handles.waitbar.text);
end
我使用带有此代码的句柄调用函数
hWait = waitbar(0,'1','Name','Reading calibration file ...');
cleanupWaitbar = onCleanup(@()(delete(hWait)));
handles.waitbar.handle = hWait;
handles.waitbar.text ='正在读取堆栈的子集...';
readCalibrationImage(handles,@z_WaitBarUpdate);
任何想法如何访问我的回调中的waitbar句柄?
我通常不使用大多数o你使用的功能,我不是一个Matlab GUI的家伙。
<$ p $
p>
function z_WaitBarUpdate(value,maxValue)
到
函数z_WaitBarUpdate(value,maxValue,handles)
更改
readCalibrationImage(handles,@z_WaitBarUpdate);
到
readCalibrationImage(handles,@(value,maxValue)z_WaitBarUpdate(value,maxValue,handles));
首先,更新功能,处理您缺少的输入。如果处理
未传递,则函数将不可用。然后,在创建句柄
结构之后,这将创建一个匿名函数,目的是定义第三个输入,同时允许稍后定义前两个输入,函数实际上被调用。
I try to implement a fall back function in my gui that updates a waitbar. I pass the function handle into the function which loads the images. The fallback itself works, but I do not get the handle to the waitbar.
function z_WaitBarUpdate(value, maxValue)
handles=guidata(handles.output); % <-- fails because handles is unknown
if ishandle(handles.waitbar.handle)
waitbar(value/maxValue,handles.waitbar.handle,handles.waitbar.text);
end
I call the function with the handle with this code
hWait = waitbar(0,'1','Name','Reading calibration file ...');
cleanupWaitbar = onCleanup( @()( delete( hWait )));
handles.waitbar.handle = hWait;
handles.waitbar.text = 'reading subset of stack ...';
readCalibrationImage( handles , @z_WaitBarUpdate);
any idea how to access the waitbar handle in my callback?
I don't typcially use most o the features you are using, I'm not a Matlab GUI guy. But, I think this would work.
Change
function z_WaitBarUpdate(value, maxValue)
to
function z_WaitBarUpdate(value, maxValue, handles)
Change
readCalibrationImage( handles , @z_WaitBarUpdate);
to
readCalibrationImage( handles , @(value, maxValue) z_WaitBarUpdate(value, maxValue, handles));
First, this defines a third input to the update function, to handle the input that you are missing. If handles
is not passed in then it will not be available to the function. Then, after the handles
structure has been created, this creates an anonymous function with the purpose of defining the third input, while allowing the first two inputs to be defined later, when the function is actually called.
这篇关于回调函数在gui中不知道句柄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!