1

I'm having a really weird problem that I really can't figure it out. So I have this Box object that I created in an header file:

#ifndef BOX_H
#define BOX_H

class Box
{
public:
    Box(string newName);
    ~Box();
            //...

};

#endif // BOX_H

Then I have this BoxTable class in another header file:

#ifndef BOXTABLE_H
#define BOXTABLE_H

#include <QTableWidget>
#include "box.h"

class BoxTable : public QTableWidget
{

Q_OBJECT

public:
    BoxTable(QWidget* parent = 0, int rows = 0);
    ~BoxTable();

    void setBox(int row, Box* a); //here
    //...

};

#endif // BOXTABLE_H

To me this is all correct, but when I compile I get this error:

error: 'Box' is not a type

on the line that I commented with "here".

Does anyone know what I'm doing wrong? I would really appreciate the help. If you need more details just ask.

Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740
  • it doesn't complain about the line just above "here"? – Janus Troelsen May 14 '13 at 22:21
  • Run it through the pre-processor and see what's really happening. – Peter Wood May 14 '13 at 22:24
  • that was a mistake, but yes it complains – user2383595 May 14 '13 at 22:36
  • i deleted that line now. Run through the pre-processor? That's new to me, how do i do that? – user2383595 May 14 '13 at 22:37
  • Are you still getting errors? Can you provide what exactly is that your IDE is saying? – Miguel May 14 '13 at 22:40
  • The IDE is giving me just the error i said:boxtable.h:17: error: 'Box' is not a type – user2383595 May 14 '13 at 22:41
  • Well, I don't know if you decided to omit some code in order to post it here but I see a couple of things missing. Where is #include that should be on top of the Box header. Also, what exactly is Q_OBJECT? If it's nothing then you need to comment it out, and if it is that's not a proper variable declaration.... – Miguel May 14 '13 at 22:50
  • Well noticed, but yes i omitted some code, not related to this, the string header is there. The Q_OBJECT is a macro used by Qt, i never understood very well why is it needed but it must be there like it is. I'm still learning... so sorry i couldn't explain very well – user2383595 May 14 '13 at 22:57
  • @user2383595 Usually your tool's documentation will tell you which build options to change to create pre-processed output. – Peter Wood May 15 '13 at 07:27
  • It's quite possible that `BOX_H` isn't unique enough, and a different header with the same `#define` is preventing your header from being included. – Peter Wood May 15 '13 at 07:28
  • If Q_OBJECT is supposed to be a macro you need to find out how it needs to be used. The macros should always be on top of the header files and a #define should precede it. Can you post the actual code please. – Miguel May 16 '13 at 00:31
  • @Miguel `Q_OBJECT` is a Qt macro, which is preprocessed by `moc`, the meta-object compiler. It enables, amongst other things, signals and slots. See [What does the macro Q_OBJECT do?](http://stackoverflow.com/questions/1368584/qt-question-what-does-the-q-object-macro-do-why-do-all-qt-objects-need-this-ma). – Peter Wood May 16 '13 at 20:24
  • Is there any chance that `BOX_H` is defined anywhere other than `box.h`? – Mark Ransom Dec 29 '13 at 14:01

0 Answers0