kja
13th November 2010, 01:47
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?
#include <QtGui>
#include <QApplication>
#include <QVBoxLayout>
#include <QLineEdit>
#include <QPushButton>
#include "qobjectdefs.h"
class myCanvas : public QWidget{
Q_OBJECT //this program runs fine if i comment out Q_OBJECT
public:
myCanvas (QWidget * parent = 0);
public Q_SLOTS:
void copyText(const QString & text);
};
myCanvas::myCanvas(QWidget *parent):QWidget(parent){
QLineEdit * lineedit = new QLineEdit;
QPushButton * pushbutton = new QPushButton("Enter");
QVBoxLayout * layout = new QVBoxLayout;
layout->addWidget(lineedit);
layout->addWidget(pushbutton);
setLayout(layout);
}
int main (int argc, char * argv[])
{
QApplication app (argc, argv);
myCanvas bob;
bob.show();
return app.exec();
}
errors with Q_OBJECT uncommented:
1>Linking...
1>connectWorking.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall myCanvas::metaObject(void)const " (?metaObject@myCanvas@@UBEPBUQMetaObject@@XZ)
1>connectWorking.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall myCanvas::qt_metacast(char const *)" (?qt_metacast@myCanvas@@UAEPAXPBD@Z)
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@@HP APAX@Z)
1>...\Debug\funcLoadData.exe : fatal error LNK1120: 3 unresolved externals
1>funcLoadData - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
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?
#include <QtGui>
#include <QApplication>
#include <QVBoxLayout>
#include <QLineEdit>
#include <QPushButton>
#include "qobjectdefs.h"
class myCanvas : public QWidget{
Q_OBJECT //this program runs fine if i comment out Q_OBJECT
public:
myCanvas (QWidget * parent = 0);
public Q_SLOTS:
void copyText(const QString & text);
};
myCanvas::myCanvas(QWidget *parent):QWidget(parent){
QLineEdit * lineedit = new QLineEdit;
QPushButton * pushbutton = new QPushButton("Enter");
QVBoxLayout * layout = new QVBoxLayout;
layout->addWidget(lineedit);
layout->addWidget(pushbutton);
setLayout(layout);
}
int main (int argc, char * argv[])
{
QApplication app (argc, argv);
myCanvas bob;
bob.show();
return app.exec();
}
errors with Q_OBJECT uncommented:
1>Linking...
1>connectWorking.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall myCanvas::metaObject(void)const " (?metaObject@myCanvas@@UBEPBUQMetaObject@@XZ)
1>connectWorking.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall myCanvas::qt_metacast(char const *)" (?qt_metacast@myCanvas@@UAEPAXPBD@Z)
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@@HP APAX@Z)
1>...\Debug\funcLoadData.exe : fatal error LNK1120: 3 unresolved externals
1>funcLoadData - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========