0

I have create a ui designer object called workspace and there is a object named myForm promoted to my custom class named CustomForm. And now I want access the object myForm in other class but I fail. In Workspace member function definition, I access myForm through ui->myForm, how can I acccess in other class?

Asuka
  • 301
  • 4
  • 16
  • 2
    Please be specific and show some minimal example. I just can guess what your problem is. If you want to access your Form from outside your ui-based class you have to keep in mind that the ui is private by default. Accessing ui-elements directly from outside the ui-based class is trivial by e.g. writing accessor functions but is (generally speaking) a really bad idea (design-wise). – OnWhenReady Jun 02 '16 at 07:54

1 Answers1

2

You can't access it directly as ui is generally private.

But you can add a getter function (CustomForm *myForm()) that returns ui->myForm to your Workspace class.

Benjamin T
  • 8,120
  • 20
  • 37
  • Thanks, it helps me – Asuka Jun 02 '16 at 13:49
  • OnWhenReady's [comment](http://stackoverflow.com/questions/37585269/qt5-how-to-access-object-in-ui-designer/37585912?noredirect=1#comment62657202_37585912) is also good to keep in mind as you generally don't want to expose child widgets. Requiring a direct access on a child widget can be a sign of a flaw in your software design. – Benjamin T Jun 02 '16 at 22:55