Search code examples
c++qtqlist

Qt C++ - Creation QList<Myclass> - is not a valid template type argument for parameter 'T


I have just started with C++ Qt and I wrote the following .h file: The .cpp file contains only empty constructors and destructors.

#include <QList>

class XML_Files
{

public:
    XML_Files();
    ~XML_Files();

protected:
    QList<Myclass> m_Xmls;

};


class Myclass
{
public:
    Myclass();
    ~Myclass();

protected:

    int a;

};

but I keep getting the following errors:

error C2065: 'Myclass': undeclared identifier
error C2923: 'QList': 'Myclass' is not a valid template type argument for parameter 'T'

What do I have to do to declare a Qlist with my own data type?


Solution

  • You can't use the name MyClass until the compiler knows about it. Since you do not declare MyClass until after XML_Files you cannot use it's name in XML_Files.

    The simplest solution here is to just change the order of the declarations and declare MyClass before XML_Files.