Results 1 to 8 of 8

Thread: hint on OO

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default hint on OO

    HI, I have mainform class that has got a member object WIDGETGL; widgetGL show some GL objects that are members of StructureGL; there's only one instance of StructureGL (ok); I declared it as global variabile inside mainform.ui.h; in others part of app that StructureGL is request I used extern declaration...
    Qt Code:
    1. //mainform.ui.h
    2. StructureGL strutGL;
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. //WIDGETGL.cpp
    2. extern StructureGL strutGL;
    3. void WIDGETG::paintGL()
    4. structGL.drawSPhere();
    To copy to clipboard, switch view to plain text mode 
    the question: can it be ok? Is it better declare strutGL as member of mainform class? or what? thanks...
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: hint on OO

    In general globals in C++ are bad practice (seldom they are really needed)
    Is there anything preventing you from making something like:
    Qt Code:
    1. //define in widgetg.h: StructureGL m_structGL;
    2. void WIDGETG::setStructure(const StructureGL &strutGL)
    3. {
    4. m_structGL = structGL;
    5. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: hint on OO

    is make strutGL member of MainForm class a bad idea? mainform must use strutGL....
    Regards

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: hint on OO

    Could you elaborate on the problem you have?
    What it is you want to do, and what are the alternatives you are considering to acheive it?

  5. #5
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: hint on OO

    mainform class need to use that structGL and widgetGL too; I wonder if an instance of structGL as member of mainform class is likely...you just said avoid global variabiles.....
    Regards

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: hint on OO

    What is the relationship between mainform and widgetGL?
    Is one a member of the other?
    Can one access the other?
    Is there another object that sees them both?

  7. #7
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: hint on OO

    Quote Originally Posted by high_flyer
    What is the relationship between mainform and widgetGL?
    Is one a member of the other?
    Can one access the other?
    Is there another object that sees them both?
    widgetGL is member of MainForm; widgetGL can access to MainForm class and viceversa;
    there isn't object that can see both them..
    Regards

  8. #8
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: hint on OO

    So what is the problem then?
    If both classes need to access the same element, and one class is a member of the other then just make structGL member in MainForm and pass it to and from widgetGL the way I showed in the beginning.

Similar Threads

  1. QDockArea size hint
    By ksierens in forum Qt Programming
    Replies: 2
    Last Post: 5th April 2006, 15:37

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.