paie
5th August 2011, 22:39
I've been all over google trying to understand why I can't get this to work
I've tried all kinds of things I've seen out there, even including the source file (ugh!) but whenever I'm not getting compiler errors, I'm getting linker errors.
OK, maybe I'm just a rube.
Anyway the code below is throwing this compiler exception.
LNK2019 unresolved external symbol public: virtual __thiscall ControlGroup<class QRadioButton> .. yada ... yada ... yada
Here is the code that declares an instance of the template in a header file.
bits.h
#include "controlgroup.h"
class Ui_bits
{
public:
ControlGroup<QRadioButton> *pBitSize;
}
Here's the call that invokes the template and incurs the wrath of the linker.
bits.cpp
#include "bits.h"
void some_init_func()
{
Twidget tw;
ui->pBitSizes = new ControlGroup <QRadioButton>(&tw, ui->centralWidget);
}
Here is the header for the offending template class...
controlgroup.h
#ifndef CONTROLGROUP_H
#define CONTROLGROUP_H
#include <QtCore>
#include <QtGui>
typedef void (*pf)(int);
class Twidget
{
public:
QString name;
QSignalMapper mapper;
QList <pf> slotList;
int count;
};
template <typename T>
class ControlGroup : public QWidget
{
public:
explicit ControlGroup(Twidget *tw, QWidget *parent=0)
{
init (tw, parent );
}
ControlGroup(){};
void init( Twidget *tw, QWidget *parent);
~ControlGroup();
QList<T> widget;
private:
Twidget *m_tw;
QWidget *m_parent;
#include "controlgroup.cpp"
};
#endif // CONTROLGROUP_H
... and here's the source ...
controlgroup.cpp
#ifndef CONTROLGROUP_CPP
#define CONTROLGROUP_CPP
#include "controlgroup.h"
template <typename T>
void init( Twidget *tw, QWidget *parent )
{
for (int index = 0; index < tw->count; index++)
{
widget.append(new <T>(parent));
}
}
#endif
I'm sure it's something stupid, and that you guys frequently see ignorance like this.
It's probably a face-palmer, but I just can't figure it out.
I've tried all kinds of things I've seen out there, even including the source file (ugh!) but whenever I'm not getting compiler errors, I'm getting linker errors.
OK, maybe I'm just a rube.
Anyway the code below is throwing this compiler exception.
LNK2019 unresolved external symbol public: virtual __thiscall ControlGroup<class QRadioButton> .. yada ... yada ... yada
Here is the code that declares an instance of the template in a header file.
bits.h
#include "controlgroup.h"
class Ui_bits
{
public:
ControlGroup<QRadioButton> *pBitSize;
}
Here's the call that invokes the template and incurs the wrath of the linker.
bits.cpp
#include "bits.h"
void some_init_func()
{
Twidget tw;
ui->pBitSizes = new ControlGroup <QRadioButton>(&tw, ui->centralWidget);
}
Here is the header for the offending template class...
controlgroup.h
#ifndef CONTROLGROUP_H
#define CONTROLGROUP_H
#include <QtCore>
#include <QtGui>
typedef void (*pf)(int);
class Twidget
{
public:
QString name;
QSignalMapper mapper;
QList <pf> slotList;
int count;
};
template <typename T>
class ControlGroup : public QWidget
{
public:
explicit ControlGroup(Twidget *tw, QWidget *parent=0)
{
init (tw, parent );
}
ControlGroup(){};
void init( Twidget *tw, QWidget *parent);
~ControlGroup();
QList<T> widget;
private:
Twidget *m_tw;
QWidget *m_parent;
#include "controlgroup.cpp"
};
#endif // CONTROLGROUP_H
... and here's the source ...
controlgroup.cpp
#ifndef CONTROLGROUP_CPP
#define CONTROLGROUP_CPP
#include "controlgroup.h"
template <typename T>
void init( Twidget *tw, QWidget *parent )
{
for (int index = 0; index < tw->count; index++)
{
widget.append(new <T>(parent));
}
}
#endif
I'm sure it's something stupid, and that you guys frequently see ignorance like this.
It's probably a face-palmer, but I just can't figure it out.