Results 1 to 3 of 3

Thread: Connection of custon signals/slots

  1. #1
    Join Date
    Aug 2007
    Posts
    64
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Connection of custon signals/slots

    Ok

    I've implemented custom signal/slots:

    Qt Code:
    1. #ifndef PORTA_H
    2. #define PORTA_H
    3. #include <QObject>
    4.  
    5. class Porta : public QObject{
    6. public:
    7. static const int DISCRETE=0;
    8. static const int BINARY=1;
    9.  
    10. Porta ();
    11. int getValue ();
    12. virtual void setType (int t);
    13.  
    14. protected:
    15. int value;
    16. pthread_t thread;
    17. int type;
    18.  
    19. int createThread ();
    20. static void *startThread (void *obj);
    21. virtual void threadFunction(void)=0;
    22.  
    23. signals:
    24. void valueChanged();
    25. };
    26.  
    27. #endif
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. #include "PortaEntrada.h"
    2.  
    3. #include <iostream>
    4.  
    5. using namespace std;
    6.  
    7. PortaEntrada::PortaEntrada(){
    8. oscilation=BINARY;
    9. }
    10.  
    11. void PortaEntrada::threadFunction(void){
    12. while(1){
    13. doGenerate();
    14. sleep(5);
    15. }
    16. }
    17.  
    18. int PortaEntrada::doGenerate(){
    19. value=generator->generate();
    20. emit valueChanged();
    21. return(value);
    22. }
    23.  
    24. void PortaEntrada::setOscilation (int o){
    25. oscilation=o;
    26. switch(oscilation){
    27. case QUADRATIC : generator=new (QGenerator);
    28. break;
    29. case TRIANGULAR : generator=new (TGenerator);
    30. break;
    31. case CONSTANT : generator=new (CGenerator);
    32. break;
    33. default : generator=new (BGenerator);
    34. break;
    35. }
    36. createThread();
    37. }
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. #include "SpinView.h"
    2. #include <iostream>
    3.  
    4. using namespace std;
    5.  
    6. SpinView::SpinView(QWidget *parent):QSpinBox(parent){
    7. }
    8.  
    9.  
    10. void SpinView::setModel(Porta *m){
    11. View::setModel(m);
    12. connect(model,SIGNAL(valueChanged()),this,SLOT(setInView()));
    13. }
    14.  
    15. void SpinView::setInValue(void){
    16. setValue(model->getValue());
    17. }
    To copy to clipboard, switch view to plain text mode 

    but when I run the program:

    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'dInSpin1')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'aInSpin1')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'dOutSpin1')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'aOutSpin6')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'dInSpin2')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'aInSpin2')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'dOutSpin2')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'aOutSpin7')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'dInSpin3')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'aInSpin3')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'dOutSpin3')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'aOutSpin8')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'dInSpin4')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'aInSpin4')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'dOutSpin4')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'aOutSpin9')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'dInSpin5')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'aInSpin5')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'dOutSpin5')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'aOutSpin10')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'dInSpin6')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'aInSpin6')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'dOutSpin6')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'aOutSpin1')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'dInSpin7')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'aInSpin7')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'dOutSpin7')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'aOutSpin2')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'dInSpin8')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'aInSpin8')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'dOutSpin8')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'aOutSpin3')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'dInSpin9')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'aInSpin9')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'dOutSpin9')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'aOutSpin4')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'dInSpin10')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'aInSpin10')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'dOutSpin10')
    Object::connect: No such signal QObject::valueChanged()
    Object::connect: (receiver name: 'aOutSpin5')
    How can I connect this custom signal with my custom slot??

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Connection of custon signals/slots

    You need to define Q_OBJECT macro in your class to enable it to use signals and slots.
    Qt Code:
    1. class Porta : public QObject{
    2. Q_OBJECT
    3. public:
    4. // ur rest of the code
    To copy to clipboard, switch view to plain text mode 

    that must do i guess

  3. #3
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 162 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Connection of custon signals/slots

    also note the memory leak in setOscilation()

Similar Threads

  1. SQL connection closure problem.
    By cbarmpar in forum Qt Programming
    Replies: 1
    Last Post: 8th September 2008, 09:42
  2. Client/Server Error: BadIDChoice
    By 3nc31 in forum Qt Programming
    Replies: 5
    Last Post: 27th November 2007, 11:22

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.