Writing to form fields from other files than mainwindow.h
-
Hi,
I'm trying to populating some form fields.
If I reference them from mainwindow.cpp (which includes "ui.mailwindow.h") it can see them fine and works okay.I wish to reference them from another file of my own creation.
I've added #include "ui_mainwindow.h" and #include "mainwindow.h" but it totally fails to recognise them.Can someone tell me where I'm going wrong here?
Thanks.
-
Hi,
I'm trying to populating some form fields.
If I reference them from mainwindow.cpp (which includes "ui.mailwindow.h") it can see them fine and works okay.I wish to reference them from another file of my own creation.
I've added #include "ui_mainwindow.h" and #include "mainwindow.h" but it totally fails to recognise them.Can someone tell me where I'm going wrong here?
Thanks.
@Uberlinc
You are trying to doing the wrong thing, and in the wrong way :)-
Never
#include ui_....h
file into any file other than the.cpp
of the same name. Regard it as a "private" include for that file only. -
If you do want to access another class/form,
#include "thatclass.h"
only. You must then go intothatclass.{cpp,h}
and export whatever you need to access explicitly, by writing appropriatepublic
methods to access just what is needed from there. -
However, you should never do that in the case of
mainwindow
. No other class/form should know about, or need to know about, anything in your main window. Indeed, other classes/forms should not even know or care whether there is any main window. Main window can know about the forms/classes it uses, but not the other way round. So why would you want or need to in your situation? If you do need to communicate, use signals/slots for this purpose.
Thing of it like parents & children in real life. Parents can manipulate and instruct children what to do directly, if necessary. But children aren't allowed to do that to their parents; at best they can send little message-signals, which their parents can pick up and act on or ignore. At least that's what the relationship should look like. :D
-