UIDesigner.exe 多控件时退出

DUILIB UIDesigner.exe 多个控件布局的时候 总是会crash

在使用UIDesigner.exe  多个控件布局总是出错。发现代码crash在
void CMultiUITracker::ExcludeChildren(CArray<CControlUI*,CControlUI*>& arrSelected)
函数中,修改后正常。
void CMultiUITracker::ExcludeChildren(CArray<CControlUI*,CControlUI*>& arrSelected)
{
int size = arrSelected.GetSize();
int* pDepth = new int[size];
for(int i=0; i<size; i++)
{
ExtendedAttributes* pExtended = (ExtendedAttributes*)arrSelected[i]->GetTag();
pDepth[i] = pExtended->nDepth;
}

for(int i=0; i<arrSelected.GetSize()-1; i++)
{
CControlUI* pControl1 = arrSelected[i];
for(int j=i+1; j<arrSelected.GetSize(); j++)
{
if(pDepth[i] != pDepth[j])
{
CControlUI* pControl2 = arrSelected[j];

if (pControl2)
{
if (pDepth[i] < pDepth[j])
{
int depth = pDepth[j] - pDepth[i];
while (depth--)
{
CControlUI* tmp = pControl2->GetParent();
if (tmp)
{
pControl2 = tmp;
}
else
{
break;
}
}

if (pControl1 == pControl2)
{
arrSelected.RemoveAt(j--);
}
}
else
{
int depth = pDepth[i] - pDepth[j];
while (depth--)
{
CControlUI* tmp = pControl1->GetParent();
if (tmp)
{
pControl1 = tmp;
}
else
{
break;
}
}

if (pControl1 == pControl2)
{
arrSelected.RemoveAt(i--);
}
}
}
}
}
}

delete[] pDepth;
}
在 MATLAB App Designer 中,可以通过使用 `uicontrol` 控件来创建按钮,然后通过 `buttonDownFcn` 回调函数来实现按钮的点击事件。 下面是一个示例代码,演示了如何在一个循环中,通过点击按钮来退出循环: ```matlab classdef MyCode < matlab.apps.AppBase % Properties properties (Access = private) % 控件 Button matlab.ui.control.Button Label matlab.ui.control.Label % 循环状态 IsRunning logical = true end % App 构造函数 methods (Access = private) function createComponents(app) % 创建控件 app.Button = uibutton(app.UIFigure, 'push', ... 'Position', [100 100 100 30], ... 'Text', '停止', ... 'ButtonDownFcn', @app.onButtonClick); app.Label = uilabel(app.UIFigure, ... 'Position', [100 150 200 30], ... 'Text', '循环正在运行...'); end end % App 回调函数 methods (Access = private) % 按钮点击事件 function onButtonClick(app, ~, ~) % 修改循环状态 app.IsRunning = false; % 修改按钮文本 app.Button.Text = '已停止'; % 修改标签文本 app.Label.Text = '循环已停止。'; end % 循环函数 function runLoop(app) while app.IsRunning % 做一些计算... % 检查按钮状态 drawnow; if ~isvalid(app.Button) || ~app.Button.Enable break; end end end end % App 生命周期函数 methods (Access = protected) % 创建 UIFigure 和组件 function createUIFigure(app) app.UIFigure = uifigure; app.UIFigure.Position = [100 100 300 300]; app.UIFigure.Name = 'MyCode'; % 创建组件 createComponents(app); % 运行循环 runLoop(app); end % 关闭 UIFigure 调用 function delete(app) % 停止循环 app.IsRunning = false; % 销毁控件 delete(app.Button); delete(app.Label); % 调用父类的 delete 方法 delete@matlab.apps.AppBase(app); end end end ``` 在这个示例代码中,我们创建了一个 `Button` 按钮,点击按钮会触发 `onButtonClick` 回调函数。在 `runLoop` 循环函数中,我们检查 `Button` 控件是否处于无效状态,如果是则退出循环。 注意,我们需要在 `runLoop` 函数中使用 `drawnow` 函数,以便及处理按钮的点击事件。同,我们在 `delete` 函数中停止循环,并销毁控件
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值