GUI handles in classes problem

조회 수: 5 (최근 30일)
Ruben
Ruben 2012년 6월 11일
Hello,
I'm writing an OO gui program and I'm having issues trying to use the set() function to change GUI element properties. I'm simply trying to change a buttons enable property from off to on. I have attached abridged code showing the same problem below. My world is c++ programming and the way matlab handles classes etc feels rather strange so the problem might simply be caused by my misunderstanding of the system. Anyway, when I attempt to use the set() function on the handle AD.buttonExit, it works as expected when I execute the command in the initUI() function. If I try to do the same in a different function, it fails. I checked the stacks by simply printing the contens of AD. In the initUI function it clearly shows a handle value for buttonExit, it doesn't in the constructor function (or any other class-member-function). I feel like I'm making a elementary mistake, however I don't see it and I hope someone might be able to assist me.
Kind regards, Ruben Higler
code (abridged for clarity):
classdef test
properties
AppUI;
buttonExit;
end
methods
function AD = test()
%draws UI
AD.initUI();
set(AD.buttonExit, 'Enable', 'on')
AD.test2()
end
function initUI(AD)
AD.AppUI = figure('Visible','off','Position',[520,321,695,482], 'MenuBar', 'none', 'Name', '3D Particle Tracking',...
'NumberTitle', 'off', 'Resize', 'off', 'Color', [0.94,0.94,0.94]);
AD.buttonExit = uicontrol('Enable', 'off', 'Style', 'pushbutton', 'Visible', 'on', 'Position', [35,29,181,31], 'String', 'Exit');
set(AD.AppUI, 'Visible', 'on');
%1 set(AD.buttonExit, 'Enable', 'on')
end
function test2(AD)
set(AD.buttonExit, 'Enable', 'on')
end
end
end

답변 (1개)

per isakson
per isakson 2012년 6월 16일
In Matlab the connection between "handle" in "Handle Graphic" and handle classes in the OO-system is that both are "references" to objects, however objects of quite different kinds.
In the Matlab OO-system there are value and handle classes. The former is immutable and the latter mutable.
Your class, test, need to inherit from handle to behave the way you expect. Change the first line of the code to
classdef test < handle
  댓글 수: 2
Jette
Jette 2012년 10월 10일
Does this mean that all GUI-classes need to be handle classes? Do you know a documentation or tutorial dealing with GUIs using OOP?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Handle Classes에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by