Results 1 to 8 of 8

Thread: simple question on Class-Members

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

    Default simple question on Class-Members

    Hi, I have a question:
    Qt Code:
    1. class DOOR {
    2. public:
    3. ........
    4. draw();
    5. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. class build {
    2. public:
    3. ........
    4. std::vector<DOOR> door;
    5. QImage imm;
    6. };
    To copy to clipboard, switch view to plain text mode 
    I need to use variable imm within member draw(). How can I do?
    Thanks
    Last edited by mickey; 4th February 2006 at 13:38.
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: simple question on Class-Members

    What calls that DOOR::draw() method? Maybe you invoke it only from build class?

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

    Default Re: simple question on Class-Members

    Qt Code:
    1. void DOOR::draw() {
    2. imm="hello\n";
    3. }
    To copy to clipboard, switch view to plain text mode 

    I'd like use imm in ::draw () and I'd like can use "only" imm and not other variables of Build class.....
    Last edited by mickey; 4th February 2006 at 16:10.
    Regards

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: simple question on Class-Members

    Quote Originally Posted by mickey
    I'd like use imm in ::draw () and I'd like can use "only" imm and not other variables of Build class.....
    But where do you intend to use thet DOOR::draw() method?

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

    Default Re: simple question on Class-Members

    now I don't know.
    I'd like use imm within Door:draw() and compile it.
    Thanks.
    Regards

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: simple question on Class-Members

    Quote Originally Posted by mickey
    now I don't know.
    So maybe you should redesign your classes?

    For example like this:
    Qt Code:
    1. void DOOR::draw( const QImage& img )
    2. {
    3. // ...
    4. }
    5.  
    6. void build::draw()
    7. {
    8. // ...
    9. for( std::vector<DOOR>::iterator it = door.begin(); it != door.end(); ++it ) {
    10. it->draw( imm );
    11. }
    12. // ...
    13. }
    To copy to clipboard, switch view to plain text mode 
    Other possibility is that each of DOOR instances would hold a pointer or reference to a build instance:
    Qt Code:
    1. void DOOR::draw()
    2. {
    3. // ...
    4. QImage img( _build->image() );
    5. // ...
    6. }
    7.  
    8. const QImage& build::image() const
    9. {
    10. return _imm;
    11. }
    To copy to clipboard, switch view to plain text mode 
    Everything depends on the way you want to use those two classes and on things what they represent.

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

    Default Re: simple question on Class-Members

    OK thanks. But why do you use underscore symbol?
    Regards

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: simple question on Class-Members

    Quote Originally Posted by mickey
    why do you use underscore symbol?
    In this case is just a habit.

    In my code I add underscore to member variables to distinguish them from parameters.

Similar Threads

  1. Simple RAII question with Qt
    By maverick_pol in forum Qt Programming
    Replies: 4
    Last Post: 12th November 2008, 15:39
  2. Replies: 0
    Last Post: 2nd September 2008, 05:29
  3. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 08:57
  4. templates / Q_OBJECT question
    By _borker_ in forum Qt Programming
    Replies: 6
    Last Post: 19th December 2007, 21:35
  5. Replies: 4
    Last Post: 26th June 2007, 20:19

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.