Why should I declare again ?

F

Fisherss

Hi all
I am a C++ newbie and now have a problem with this:

=====
#include <QtGui>
class QLabel;
=====

I am pretty sure that "QLabel" was defined in <QtGui> but I can't use
this class without "class QLabel", why should I declare it again?
 
P

Pavel Shved

Hi all
I am a C++ newbie and now have a problem with this:

=====
#include <QtGui>
class QLabel;
=====

I am pretty sure that "QLabel" was defined in <QtGui> but I can't use
this class without "class QLabel", why should I declare it again?

From FAQ: provide minimal *compilable* example that illustrates the
problem. What do you mean by `use' here?

For now: are you sure that you've *really* have the class declared?
And what is that QtGui mythical header that surely not belongs to Qt
includes as they're named with lowercase letters and .h in the end?
Or... You try to include a *directory* full of headers (which QtGui
is)?
 
E

Erik Wikström

From FAQ: provide minimal *compilable* example that illustrates the
problem. What do you mean by `use' here?

For now: are you sure that you've *really* have the class declared?
And what is that QtGui mythical header that surely not belongs to Qt
includes as they're named with lowercase letters and .h in the end?
Or... You try to include a *directory* full of headers (which QtGui
is)?

And: What makes you think you should declare QLable?
 
D

Duane Hebert

Fisherss said:
Hi all
I am a C++ newbie and now have a problem with this:

=====
#include <QtGui>
class QLabel;
=====

I am pretty sure that "QLabel" was defined in <QtGui> but I can't use this
class without "class QLabel", why should I declare it again?

QtGui is the library. You need to link it, not include it.
If you could it would not be a good idea anyway.
How you link it depends on your tools,

For QLabel, forward declare it in the header as you show
and in the cpp file, add the #include <QLabel>
 
F

Fisherss

Duane said:
QtGui is the library. You need to link it, not include it.
If you could it would not be a good idea anyway.
How you link it depends on your tools,

For QLabel, forward declare it in the header as you show
and in the cpp file, add the #include <QLabel>
Thanks, I think this should be the right solution.
 
E

Erik Wikström

The compiler gave me a message that QLable was not declared.

In your case that probably means that you should include <qlabel.h> and
not just make a forward declaration.
 
D

Duane Hebert

Erik Wikström said:
In your case that probably means that you should include <qlabel.h> and
not just make a forward declaration.

Starting with Qt4, the trolls changed their includes to use the
<QLabel> format. Since he has <QtGui> it seems that
he's using Qt4.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,181
Messages
2,570,970
Members
47,536
Latest member
VeldaYoung

Latest Threads

Top