Results 1 to 3 of 3

Thread: How to access myApp->method from a child

  1. #1
    Join Date
    Jan 2008
    Posts
    155
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default How to access myApp->method from a child

    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.
    MacOSX user dabbling with Linux and Windows.

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to access myApp->method from a child

    one way is:

    #include "your-app.h"

    Qt Code:
    1. static_cast<YourApp*>(qApp)->getConfigData()
    To copy to clipboard, switch view to plain text mode 

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

    HTH

  3. #3
    Join Date
    Jan 2008
    Posts
    155
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to access myApp->method from a child

    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.
    MacOSX user dabbling with Linux and Windows.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.