Results 1 to 3 of 3

Thread: simple signals and slots

  1. #1
    Join Date
    Jan 2006
    Posts
    75
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default simple signals and slots

    I can't get this to compile:

    Qt Code:
    1. #include <QApplication>
    2. #include <QObject>
    3.  
    4. #include "signal.h"
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication app(argc, argv);
    9.  
    10. MySignal a;
    11. MySignal b;
    12.  
    13. int ret = app.exec();
    14.  
    15. return ret;
    16. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "signal.h"
    2. #include <iostream>
    3.  
    4. MySignal::MySignal()
    5. {}
    6.  
    7. MySignal::~MySignal()
    8. {}
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #ifndef MYSIGNAL_H
    2. #define MYSIGNAL_H
    3.  
    4. #include <QObject>
    5.  
    6. class MySignal : public QObject
    7. {
    8.  
    9. public:
    10. MySignal();
    11. virtual ~MySignal();
    12.  
    13. void setInt(int);
    14.  
    15. // signals:
    16. // void send(int);
    17.  
    18. // public slots:
    19. // void received(int);
    20.  
    21. private:
    22. int value;
    23.  
    24. };
    25.  
    26. #endif
    To copy to clipboard, switch view to plain text mode 

    I keep getting this error:

    ./signal.h:6: error: invalid use of undefined type ‘struct QObject’
    /usr/include/qt4/QtCore/qobjectdefs.h:164: error: forward declaration of ‘struct QObject’

  2. #2
    Join Date
    Jan 2006
    Posts
    75
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: simple signals and slots

    This is almost too funny to be true since I've been struggling all day with QT; I think that declaring my files with the names signal.h and signal.cpp was causing the problem. I changed the names to mysignal.h and mysignal.cpp and now it compiles. There must have been some conflict there.

  3. #3
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: simple signals and slots

    I had the exact same problem yesterday morning. But the error messages were quite obscure, and it took me a couple of hours to discover the problem.

Similar Threads

  1. Signals and Slots question
    By Thoosle in forum Qt Programming
    Replies: 5
    Last Post: 5th December 2006, 00:24
  2. Nested signals and slots
    By vishva in forum Qt Programming
    Replies: 2
    Last Post: 18th August 2006, 09:47
  3. Signals and Slots in dll
    By ankurjain in forum Qt Programming
    Replies: 8
    Last Post: 29th March 2006, 08:12
  4. Order of signals and slots
    By Morea in forum Newbie
    Replies: 1
    Last Post: 26th February 2006, 22:09
  5. Problem with Signals and Slots
    By Kapil in forum Newbie
    Replies: 11
    Last Post: 15th February 2006, 11: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.