Results 1 to 3 of 3

Thread: using class objects globally??????

  1. #1
    Join Date
    Jul 2007
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default using class objects globally??????

    hello all

    i have created three classes in qt 4.2...

    say

    a.h
    b.h
    c.h

    and corres. source file

    a.cpp
    b.cpp
    c.cpp

    now i want to use the object of class which is declared in a.h and defined in a.cpp in b.cpp and c.cpp.............


    the problem is if i declare it in a.h after the class declaration and then include a.h in both b.cpp and c.cpp then its giving the linker error.......

    the error is multiple defination of class object................

    please help as this the normal way of doing it in OOPS........

    i have wraped all the .h files in the macro #ifndef #define #endif........

    thanking all in anticipation

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: using class objects globally??????

    Maybe class A could provide static methods? If not, there's always Singleton pattern..
    J-P Nurmi

  3. #3
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: using class objects globally??????

    dont do multiple defination of class object in all cpp file.
    do you want to acess same object in all cpp file then write singleton class.
    you declare singlton class in a.h and create any number of object with or without same object name in different cpp file. it will treated as same object.

Similar Threads

  1. Coin3d + Qt: SIGLNALs and SLOTs
    By vonCZ in forum Newbie
    Replies: 26
    Last Post: 15th May 2009, 07:34
  2. Creating object of other class in Run() method
    By santosh.kumar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2007, 15:05
  3. Replies: 2
    Last Post: 16th March 2007, 09:04
  4. Replies: 2
    Last Post: 4th May 2006, 19:17
  5. How to propagate from one class to another
    By mahe2310 in forum Qt Programming
    Replies: 15
    Last Post: 20th March 2006, 01:27

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.