Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Access single instance from all class
Forum Updated to NodeBB v4.3 + New Features

Access single instance from all class

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 3 Posters 520 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hiren21
    wrote on last edited by
    #1

    I am trying to access awesome object from another class . I declare this in main()

    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
        QtAwesome* awesome = new QtAwesome(&app);
        awesome->initFontAwesome();
        app.setWindowIcon(awesome->icon( "clipboard" ));
        Login w;
        w.show();
    
        return app.exec();
    }
    

    Now how do I access awesome object from Login or another class ? Is it best way to initialize a class in main() if I want to access from another class ?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Pass the pointer to Login class in some method.

      If you want to have a global, single instance object, take a look at Singleton pattern. Just a word of warning: singletons add global state to the application, which makes testing and bug fixing harder (sometimes) - I recommend keeping singleton numbers as low as possible.

      (Z(:^

      1 Reply Last reply
      4
      • Venkatesh VV Offline
        Venkatesh VV Offline
        Venkatesh V
        wrote on last edited by
        #3

        Hi @hiren21

        You can pass awesome pointer to login class when you create a object of login.

        login w(awesome);

        Thanks.

        1 Reply Last reply
        2

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved