Call Edit text from another Edit text in another Gui

조회 수: 7 (최근 30일)
nguyen
nguyen 2012년 10월 24일
in PhatHienLSB.M i have a PushMo_Callback
function PushMo_Callback(hObject, eventdata, handles)
% hObject handle to PushMo (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile( ...
{
'*.bmp','BMP (*.bmp)'; ...
'*.png','PNG(*.png)'; ...
'*.jpg', 'JPG (*.jpg)'; ...
'*.*', 'All Files (*.*)'}, ...
'Moi ban chon tep anh');
set(handles.Edit1,'String',[filename,pathname]);
TachTin.m
function TachThongDiep_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to TachThongDiep (see VARARGIN)
% Choose default command line output for TachThongDiep
handles.output = hObject;
filename=get(handles.PhatHienLSB.Edit1,'String');
set(handles.Edit2,'string',filename');
% Update handles structure
guidata(hObject, handles);
help me
--> filename=get(handles.PhatHienLSB.Edit1,'String');
-->set(handles.Edit2,'string',filename');

채택된 답변

Andrew
Andrew 2012년 10월 24일
TachTongDiep doesn't know what the handle is for PhatHienLSB. So when you call handles.PhatHienLSB.Edit1 in TachTongDiep, it doesn't know you want to use the handles structure for PhatHienLSB. You need to pass the handles structure for PhatHienLSB to TachTongDiep. See getappdata and setappdata in the Matlab documentation, or use global variables, either way:
function PushMo_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile( ...
{'*.bmp','BMP (*.bmp)'; ...
'*.png','PNG(*.png)'; ...
'*.jpg', 'JPG (*.jpg)'; ...
'*.*', 'All Files (*.*)'}, ...
'Moi ban chon tep anh');
set(handles.Edit1,'String',[filename,pathname]);
setappdata(0,'handles_PhatHienLSB',handles)
function TachThongDiep_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
handles_PhatHienLSB = getappdata(0,'handles_PhatHienLSB');
filename = get(handles_PhatHienLSB.Edit1,'String');
set(handles.Edit2,'String',filename);
At least I think that's the answer, I'm still kind of a novice though, some of the other guys here should be able to help out more.
  댓글 수: 3
Andrew
Andrew 2012년 10월 24일
Are Edit1 and Edit2 in the same GUI? I assumed Edit1 was in PhatHienLSB and Edit2 was in TachThongDiep.
If you are getting that error then the problem is with
setappdata(0,'handles_PhatHienLSB',handles)
Make sure that you have that line at the end of PushMo. I tried it and it worked.
nguyen
nguyen 2012년 10월 24일
ok. it worked. Thank you very much

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Objects에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by