Results 1 to 5 of 5

Thread: want to use signal in the class itself..

  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 want to use signal in the class itself..

    Qt Code:
    1. class TrainNavigation:public QWidget
    2. {
    3. ...
    4. private:
    5. QPushButton *recordButton;
    6.  
    7. public slots:void setDisableSlot();
    8.  
    9. signals:
    10. void recordClicked();
    11. ..
    12. };
    13.  
    14. void TrainNavigation::setDisable()
    15. {
    16. emit recordClicked();
    17. }
    18. void TrainNavigation::setDisableSlot()
    19. {
    20. if()
    21. recordButton->setDisabled(TRUE);
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "TrainNavigation.h"
    2. class TrainingUI:public QWidget
    3. {
    4. Q_OBJECT
    5. public:
    6. TrainNavigation *navigate;
    7.  
    8. TrainingUI();
    9. virtual ~TrainingUI();
    10. };
    11. TrainingUI::TrainingUI()
    12. {
    13. navigate = new TrainNavigation(this);
    14. connect(navigate,SIGNAL(recordClicked()),navigate,SLOT(setDisableSlot()));
    15. navigate->setDisable();
    16. }
    To copy to clipboard, switch view to plain text mode 

    In the above code i was thinking that some how i should tell in the if condition in my
    TrainNavigation::setDisableSlot() function that if a button is clicked then only emit the signal..
    i am doing all this because i dont want to expose my button to the higher level class that is TrainingUI class..

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: want to use signal in the class itself..

    can you give more explanation what you want to get?

  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: want to use signal in the class itself..

    Hi,,
    the only thing which i want to achieve is that that when my button is clicked i want a slot to be executed..
    buti dont want to use it this way

    Qt Code:
    1. // in the TrainingUI class
    2. connect(navigate,recordButton->clicked(),this,SLOT(setDisableSlot()));
    To copy to clipboard, switch view to plain text mode 

    because in this way i have to expose my recordButton as public which i dont want ...

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: want to use signal in the class itself..

    try this code
    Qt Code:
    1. TrainNavigation::TrainNavigation(QWidget *parent) : QWidget(parent)
    2. {
    3. connect(recordButton, SIGNAL(clicked()), SIGNAL(recordClicked()));
    4. }
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to spirit for this useful post:

    salmanmanekia (5th August 2008)

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

    Default Re: want to use signal in the class itself..

    ya ..it worked..thanks...officially ur 2nd thanks..

Similar Threads

  1. Signal in base class Slot in Subclass
    By csvivek in forum Newbie
    Replies: 7
    Last Post: 30th March 2008, 17:59
  2. send own class reference throught signal
    By ^NyAw^ in forum Qt Programming
    Replies: 3
    Last Post: 10th January 2008, 22:55
  3. How to use Signal through direct connection
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2007, 08:07
  4. Connecting to a base class signal?
    By AaronMK in forum Qt Programming
    Replies: 4
    Last Post: 26th October 2007, 23:37
  5. creating treeWidgetItem using emitted signal from thread class
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 25th June 2007, 09: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.