Why does uiwait not work during startupFcn?

17 ビュー (過去 30 日間)
James Moore
James Moore 2023 年 6 月 12 日
編集済み: Cris LaPierre 2023 年 6 月 13 日
I have a function in my app that I use to pause the program and show an alert. Most of the time it works without issue.
function PauseAlert(app, msg, title, icon)
if nargin < 4
icon = 'error';
end
beep;
uialert(app.UIFigure, msg, title,'CloseFcn','uiresume(gcbf)','Icon',icon);
drawnow;
figure(app.UIFigure);
uiwait(gcbf);
end
However, if it try to use it from within the startupFcn, the program halts on the last line with the following error message:
Error using uiwait (line 48)
Input argument must be of type figure
And it gives another error when I close the uialert message:
Warning: Error while evaluating 'CloseFcn' for dialog.
Error using uiresume (line 26)
Argument must be a Figure object.
I could probably do something like the following:
if ishghandle(h)
uiwait(gcbf)
end
but then the program wouldn't pause like I want it to.

採用された回答

Cris LaPierre
Cris LaPierre 2023 年 6 月 12 日
It sounds like the figure gcbf does not yet exist when you try to call uiwait.
  7 件のコメント
Cris LaPierre
Cris LaPierre 2023 年 6 月 13 日
Just a note that this code also works in R2023a as well. For whatever reason, when I was testing it yesterday, it did not.
James Moore
James Moore 2023 年 6 月 13 日
Yes this works for me as well. Thanks for your help, I'll mark this answer as accepted.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by