Reputation: 41347
This is a very frustrating error message in Qt Creator: ’XYZ’ does not name a type
. This usually means that there is an error in the class XYZ
that prevents the compiler from generating the type, but there are no additional hints as to what went wrong.
Any suggestions?
Upvotes: 12
Views: 40439
Reputation: 99
I found a solution for myself. Say I have class A and class B. "A.h" includes "B.h" and has instance of B as member. "B.h" includes "A.h" and has instance of A as member. Compiler gives me an error in "B.h" on line of code where member of class A is declared:
"A doesn't name type"
What I do is in "A.h" I remove #include "B.h" and place #include "B.h" to "A.cpp". And before A class declaration I write class B;
...
// #include "B.h"
class B;
class A
{
...
B m_b;
};
...
Worked for me, Good luck!
Upvotes: 2
Reputation: 6049
In my case I wasn't using the namespace the class was defined in. Contents of the header were contained within the namespace, but the source file was missing the using namespace
directive.
.h
:
namespace mynamespace {
class MyClass : public QWidget
{
...
}
}
.cpp
:
using namespace mynamespace
MyClass::MyClass(QWidget *parent) : QWidget(parent)
{
}
Upvotes: 0
Reputation: 76
I found this problem on qtcreator 3.4.1 and QT 5.4, when I replace such as
#include <QTextEdit>
with
class QTextEdit;
this problem gone.
Upvotes: 6
Reputation: 43
In your abc.cpp
make sure you include xyz.h
before including abc.h
.
No idea why swapping the two around would make a difference however it did for me.
Upvotes: 4
Reputation: 51
i just had this problem, and like Arckaroph have said : the problem is that when we include a header file in a source code file, and we use in it the directive #ifndef, we can't include it again in a header file to give a type of it's included class to a variable in source code file
example :
class1.h contains Class1 class2.h contains Class2 class2 have a private variable V with class1 type if we include class1.h in class2.CPP we can't include it in class2.h to give V a class1 type.
so we put in class2.cpp class2.h before class1.h or we delete class1.h from class2.cpp
Upvotes: 5
Reputation: 2658
in a recent QT project, where I had just installed the most recent QT (3/2011), I cured the three of these that was stopping my build by adding this...
#include <sys/types.h>
...prior to the include of the header file that was throwing the errors. That did it.
I don't know why they would distribute something that had such problems, perhaps in other systems types.h is included with something else, but not in my case, anyway. Hope that helps someone.
Upvotes: 1
Reputation: 17114
Two possibilities occur to me:
1. Perhaps you have SLOT instead of SIGNAL in a connect() call.
2. Sometimes it helps to make a gratuitous edit to the .PRO file (e.g. insert and delete a space), so that QMake gets run and the .moc files get generated.
Upvotes: 0
Reputation: 21
I believe you are declaring something of type XYZ such as
XYZ foo;
The problem is XYZ is not yet defined.
The following is my problem and my conclusion. What do you think?
My problem is I have a class ABC and a class XYZ. Class ABC has a member that is declared as a XYZ type. Class XYZ has a member that is declared as a ABC type. The compiler doesn't know what the XYZ type is yet because it has not defined it yet. Therefore the error given is 'XYZ' does not name a type.
Example Code:
class ABC{
private:
XYZ *xyz; //XYZ is not defined yet
};
class XYZ{
private:
ABC *abc; //ABC is defined above
};
Upvotes: 2
Reputation: 7777
Do you get the error from the compiler or the IDE (as a squiggly underline)? I've encountered this in Qt Creator 1.2.9 and I think it's a bug in the IDE.
Upvotes: 2
Reputation: 9154
If you're using templates, then you need to precede the class name with "typename" so that the compiler can recognize it as a type...
template <typename t> //...
Upvotes: 0
Reputation: 368201
Does #include'ing the corresponding header file help?
Upvotes: 0