PDA

View Full Version : How to access myApp->method from a child



bnilsson
13th July 2008, 12:56
Excuse a very basic question:

What is the syntax for accessing a method in the main myApp class from a child object?

To clarify:

My main document application class myApp has a method getConfigData, needed by a child document class myDocument. From inside the myDocument class, how should I call getConfigData?

Simple, but I can't find it.

caduel
13th July 2008, 13:05
one way is:

#include "your-app.h"


static_cast<YourApp*>(qApp)->getConfigData()

Of course, that is not the only way.
If the method is static, or your app class a singleton there are easier ways.

HTH

bnilsson
13th July 2008, 13:22
Thanks,

Yes, myApp should have only one instance (how do I ensure this?) , so if there is a more simple method I would be interested.

The app is a document app with some common resources to be used by the child documents.