Results 1 to 4 of 4

Thread: Signal and Slots

  1. #1
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Signal and Slots

    I'm trying to set up a class with a signal, but it fails to compile.

    Qt Code:
    1. #ifndef CONTROLDB_H
    2. #define CONTROLDB_H
    3.  
    4. #include <QString>
    5.  
    6. class ControlDB:public QObject
    7. {
    8. public:
    9. ControlDB();
    10. void ControlDB::makeControlDB();
    11. void ControlDB::setLastLog(QString);
    12. void ControlDB::setOper(QString);
    13. QString ControlDB::getLastLog();
    14. QString ControlDB::getOper();
    15.  
    16. signals:
    17. void valueChanged(QString);
    18. };
    19.  
    20. #endif // CONTROLDB_H
    To copy to clipboard, switch view to plain text mode 

    Here is the error:
    error: expected class-name before '{' token

    What am I doing wrong here?

  2. #2
    Join Date
    Nov 2009
    Posts
    14
    Thanks
    4

    Default Re: Signal and Slots

    AFAIK, you should try including the Q_OBJECT, and see if that helps:

    Qt Code:
    1. #ifndef CONTROLDB_H
    2. #define CONTROLDB_H
    3.  
    4. #include <QString>
    5.  
    6. class ControlDB:public QObject
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. ControlDB();
    12. void makeControlDB();
    13. void setLastLog(QString);
    14. void setOper(QString);
    15. QString getLastLog();
    16. QString getOper();
    17.  
    18. signals:
    19. void valueChanged(QString);
    20. };
    21.  
    22. #endif // CONTROLDB_H
    To copy to clipboard, switch view to plain text mode 
    I don't particularly see the point in placing the ControlDB:: for your member functions when it is already implied they belong to the ControlDB class.

  3. #3
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Signal and Slots

    Ok positive_4_life. I have changed the code to this:

    Qt Code:
    1. #ifndef CONTROLDB_H
    2. #define CONTROLDB_H
    3.  
    4. #include <QString>
    5.  
    6. class ControlDB:public QObject
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. ControlDB();
    12. void makeControlDB();
    13. void setLastLog(QString);
    14. void setOper(QString);
    15. QString getLastLog();
    16. QString getOper();
    17.  
    18. //signals:
    19. //void valueChanged(QString);
    20. };
    21.  
    22. #endif // CONTROLDB_H
    To copy to clipboard, switch view to plain text mode 

    Now I still get this error:
    controldb.h:7: error: expected class-name before '{' token

    I can't see anything wrong with it.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Signal and Slots

    You might want to #include a definition for QObject because QString doesn't:
    Qt Code:
    1. #include <QObject>
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Queuing problem with signal and slots
    By montylee in forum Qt Programming
    Replies: 4
    Last Post: 20th November 2009, 06:11
  2. create multiple buttons with signal and slots
    By mohanakrishnan in forum Qt Programming
    Replies: 8
    Last Post: 14th November 2009, 12:03
  3. filter signal to limited slots
    By sriky27 in forum Qt Programming
    Replies: 17
    Last Post: 26th March 2009, 16:59
  4. Signal and slots
    By villy in forum Qt Programming
    Replies: 1
    Last Post: 12th January 2007, 10:10
  5. Problem with Signal and Slots
    By Kapil in forum Installation and Deployment
    Replies: 2
    Last Post: 10th February 2006, 08:51

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.