Hi,
I'm new to qt programming and I'm trying to make some custom signals and slots but I keep getting errors when I try to do some simple examples.

I can get this program to run by commenting out Q_OBJECT, but if I leave it in i get errors, any idea why that is?

Qt Code:
  1. #include <QtGui>
  2. #include <QApplication>
  3. #include <QVBoxLayout>
  4. #include <QLineEdit>
  5. #include <QPushButton>
  6. #include "qobjectdefs.h"
  7.  
  8. class myCanvas : public QWidget{
  9. Q_OBJECT //this program runs fine if i comment out Q_OBJECT
  10. public:
  11. myCanvas (QWidget * parent = 0);
  12. public Q_SLOTS:
  13. void copyText(const QString & text);
  14. };
  15.  
  16. myCanvas::myCanvas(QWidget *parent):QWidget(parent){
  17. QLineEdit * lineedit = new QLineEdit;
  18. QPushButton * pushbutton = new QPushButton("Enter");
  19.  
  20. QVBoxLayout * layout = new QVBoxLayout;
  21. layout->addWidget(lineedit);
  22. layout->addWidget(pushbutton);
  23. setLayout(layout);
  24. }
  25.  
  26. int main (int argc, char * argv[])
  27. {
  28. QApplication app (argc, argv);
  29. myCanvas bob;
  30. bob.show();
  31. return app.exec();
  32. }
To copy to clipboard, switch view to plain text mode 

errors with Q_OBJECT uncommented:

Qt Code:
  1. 1>Linking...
  2. 1>connectWorking.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall myCanvas::metaObject(void)const " (?metaObject@myCanvas@@UBEPBUQMetaObject@@XZ)
  3. 1>connectWorking.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall myCanvas::qt_metacast(char const *)" (?qt_metacast@myCanvas@@UAEPAXPBD@Z)
  4. 1>connectWorking.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall myCanvas::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@myCanvas@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
  5. 1>...\Debug\funcLoadData.exe : fatal error LNK1120: 3 unresolved externals
  6. 1>funcLoadData - 4 error(s), 0 warning(s)
  7. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
To copy to clipboard, switch view to plain text mode