Results 1 to 4 of 4

Thread: how to infrom a different class of a change in variable..

  1. #1
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default how to infrom a different class of a change in variable..

    hi..
    this problem is more related to c++ then qt but it also requires previous info about qt so i cannot consult to any pure c++ forums and c++ forum on qtcentre seems to be quite inactive so i thought of banging my question here..
    anyways the problem is here..atlast
    in the below class scenario i inform the 'superClass' with the value of 'record_click' from 'child1',the superClass then informs 'child2's record_click of this new value...but as you can see that i am using update() function in child2 in which i do record_click-- and i wanted this change to be made to superClass and child1's record_click...i mean that record_click of these two classes should also reduce themself by one
    pls see the class 'child1' first ...then the 'super' class


    Qt Code:
    1. //in superClass
    2.  
    3. connect(myChild1,SIGNAL(recordClicked(int)),this,SLOT(requestRecord(int)));
    4.  
    5. void superClass::requestRecord(int rec_clicks)
    6. {
    7. record_clicks = rec_clicks;
    8. //emit requestedRecord(); //this is useless in this case because i wanted to also emit a signal to other widget to listen to
    9. }
    10.  
    11. void superClass::recognitionAccept() //this method is succesfully called from another class and now i want to pass the recordclick value to the child..
    12. {
    13. ..
    14. myChild2->showAcceptedProgress(record_clicks);
    15. ..
    16. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. // in my child1 class
    2. ..
    3. connect(recordButton,SIGNAL(clicked()),this,SLOT(reactToRecord()));
    4. ..
    5. void child1::reactToRecord()
    6. {
    7. record_clicks++;
    8. disableRecordButton();
    9. emit recordClicked(record_clicks);
    10. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. //in child2 class
    2.  
    3. void child2::showAcceptedProgress(int rec_clicks)
    4. {
    5. record_clicks = rec_clicks;
    6. ..
    7. update();
    8. }
    To copy to clipboard, switch view to plain text mode 

  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: how to infrom a different class of a change in variable..

    Quote Originally Posted by salmanmanekia View Post
    and i wanted this change to be made to superClass and child1's record_click...i mean that record_click of these two classes should also reduce themself by one
    Does this mean that both super class and child class have their own record_click member variables?

  3. #3
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to infrom a different class of a change in variable..

    Quote Originally Posted by jacek View Post
    Does this mean that both super class and child class have their own record_click member variables?
    ya,i think it should because i have to reduce it as i said by one which mean i have to access it,one idea can be declaring it as public maybe ,but i think i just dont want to exposs unneccesary code to other classes...,
    i have also tried some derefrencing but this also doesnt seem to work...

  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: how to infrom a different class of a change in variable..

    Quote Originally Posted by salmanmanekia View Post
    ya,i think it should because i have to reduce it as i said by one which mean i have to access it,one idea can be declaring it as public maybe ,but i think i just dont want to exposs unneccesary code to other classes...,
    i have also tried some derefrencing but this also doesnt seem to work...
    I don't quite follow you.

    Anyway if you need to use some member variable in subclasses, either make it protected or give your subclasses some protected interface.

Similar Threads

  1. nmake error during .pro compiling
    By mattia in forum Installation and Deployment
    Replies: 5
    Last Post: 18th June 2008, 10:15
  2. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 07:57
  3. Accessing to a static variable from the same class
    By xgoan in forum General Programming
    Replies: 6
    Last Post: 5th March 2007, 10:50
  4. Change base class
    By villy in forum Qt Tools
    Replies: 2
    Last Post: 20th September 2006, 11:26

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.