Call Edit text from another Edit text in another Gui
7 次查看(过去 30 天)
显示 更早的评论
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');
0 个评论
采纳的回答
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
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!