0

Using Qt 5.4 and compiling in Qt Creator.

In widget 1, there is a file-scoped QList:

static QList< Tag * > g_Tags;

Note that Tag inherits from BaseDataObject. Both Tag and BaseDataObject have private, undefined copy constructors and operator=() functions.

Also in widget 1, there is the following constructor call:

MoverDialog dlg( g_Tags, this );

In simplified form, MoverDialog.h looks like:

class MoverDialog : public QDialog
{
Q_OBJECT

public:
    ///////////////////////////////////////////////////////////////////////////////////////////
    //  Constructors/Destructor

    explicit MoverDialog(   QList< BaseDataObject * > & availableList,
                            QWidget * parent = 0 );
    virtual ~MoverDialog();

etc. etc.

When I compile this code, I get the following error:

D:\MyDocs\Projects\dsb\Src\Apps\RecipeMgr_Qt\Source\Ui\RecipeGeneralWidget.cpp:166: error: C2664: 
'MoverDialog::MoverDialog(QList<T> &,QList<T> &,QWidget *)' : cannot convert parameter 1 
from 'QList<T>' to 'QList<T> &'
with
[
    T=recipemgr::BaseDataObject *
]
and
[
    T=recipemgr::Tag *
]
and
[
    T=recipemgr::BaseDataObject *
]]

Compilation succeeds if I change the declaration of the file-scoped list to:

static QList< BaseDataObject * > g_Tags;

Why does compilation fail with the file-scoped list declared using "Tag *" like shown at the top of this posting?

Doug Beyer
  • 21
  • 1
  • 3
  • 2
    possible duplicate of [C++ Templates polymorphism](http://stackoverflow.com/questions/2203388/c-templates-polymorphism) – RA. Jan 28 '15 at 18:56
  • I read the polymorphism link and that did explain the overall issue. However, the error message states that it can't convert the "QList" to a "QList &". Ignorning the lack of template polymorphism, I would think that my list is being passed by reference as written. So why did the template polymorphism issue cause that specific error message? – Doug Beyer Jan 29 '15 at 13:46

0 Answers0