Results 1 to 3 of 3

Thread: slots and signals don't seem to be recognized

  1. #1
    Join Date
    Jul 2007
    Posts
    8
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default slots and signals don't seem to be recognized

    Hello all.

    I'm very new to Qt but I'm extremely impressed with several aspects of it, especially the documentation.
    I'm not an expert programmer (more of a hobbyist), so please feel very free to correct me.

    I'm writing a tic-tac-toe game. I've got the game engine itself working, and I'm trying to wrap it up in a nice GUI.

    One aspect of the game is going to be a grid of buttons representing the board. When a button is clicked, I want a signal to be emitted witht he coordinates of the button.

    Here's what I've got:
    Qt Code:
    1. #ifndef UISPOT_HPP
    2. #define UISPOT_HPP
    3.  
    4. #include <QPushButton>
    5. #include <QIcon>
    6.  
    7. #include "spot.hpp"
    8.  
    9. namespace ttt {
    10. class UISpot : public QPushButton {
    11. Q_OBJECT
    12. private:
    13. Spot spot_;
    14. slots:
    15. void buttonClicked();
    16. signals:
    17. void clickedAt( const Coord &coord );
    18. public:
    19. UISpot( const Spot &spot, QWidget *parent ) :
    20. QPushButton( parent ),
    21. spot_( spot ) {
    22. connect( this, SIGNAL( clicked() ),
    23. this, SLOT( buttonClicked() ) );
    24. }
    25. };
    26. }
    27.  
    28. #endif // UISPOT_HPP
    To copy to clipboard, switch view to plain text mode 

    And uiSpot.cpp:

    Qt Code:
    1. #include "uiSpot.hpp"
    2.  
    3. namespace ttt {
    4. void UISpot::buttonClicked() {
    5. emit clickedAt( spot_.coord() );
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 

    The Spot interface is irrelevent, so I didn't post it. Now, when I try to compile this, I get the following error messages:

    $ qmake -project
    $ qmake
    $ make
    ...
    <SNIP>
    ...
    g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -o uiSpot.o uiSpot.cpp
    uiSpot.hpp:15: error: expected primary-expression before ‘void’
    uiSpot.hpp:15: error: ISO C++ forbids declaration of ‘type name’ with no type
    uiSpot.hpp:15: error: expected ‘;’ before ‘void’
    uiSpot.cpp:4: error: no ‘void ttt::UISpot::buttonClicked()’ member function declared in class ‘ttt::UISpot’
    make: *** [uiSpot.o] Error 1
    At line 15 is where I declare the slots and signals. What am I doing wrong?

    Any help would be greatly appreciated.
    Last edited by jacek; 1st August 2007 at 15:53. Reason: changed [code] to [quote]

  2. #2
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: slots and signals don't seem to be recognized

    I've never seen 'slots:' in a class without a visibility specification. It might not be the error, but it is worth a try. In your case, I guess that would be 'private slots:'.

    Also, you might be interested in auto-connect slots. It's a Qt slot naming convention (on_<object>_<signal>). If you call your slot 'on_this_clicked()', you don't need to explicitly connect.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  3. The following user says thank you to Michiel for this useful post:

    Jessehk (31st July 2007)

  4. #3
    Join Date
    Jul 2007
    Posts
    8
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: slots and signals don't seem to be recognized

    Quote Originally Posted by Michiel View Post
    I've never seen 'slots:' in a class without a visibility specification. It might not be the error, but it is worth a try. In your case, I guess that would be 'private slots:'.

    Also, you might be interested in auto-connect slots. It's a Qt slot naming convention (on_<object>_<signal>). If you call your slot 'on_this_clicked()', you don't need to explicitly connect.
    Thanks Michiel. The private slots did it.

Similar Threads

  1. Signals and Slots question
    By Thoosle in forum Qt Programming
    Replies: 5
    Last Post: 5th December 2006, 01:24
  2. Nested signals and slots
    By vishva in forum Qt Programming
    Replies: 2
    Last Post: 18th August 2006, 10:47
  3. Signals and Slots in dll
    By ankurjain in forum Qt Programming
    Replies: 8
    Last Post: 29th March 2006, 09:12
  4. Order of signals and slots
    By Morea in forum Newbie
    Replies: 1
    Last Post: 26th February 2006, 23:09
  5. Problem with Signals and Slots
    By Kapil in forum Newbie
    Replies: 11
    Last Post: 15th February 2006, 12:35

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.