Qt: invalid use of incomplete type and forward declaration

c++, qt

Solution

Check you ui_B.h. At the end of it, you should see

namespace Ui {
    class B: public Ui_B {};
}

If it's not, you can open you .ui file in Qt Designer, select your widget, and in Object Inspector, change the string under 'Object' to 'B'. The default value is 'Dialog' if your widget is a dialog.

Don't modify ui_B.h directly since it's generated by Qt compiler and it will be overwritten every time you compile.

Problem

I have some misunderstanding: A.h ``` #ifndef A_H #define A_H #include "B.h" class A : public B { Q_OBJECT public: A(); }; #endif ``` A.cpp ``` #include "A.h" A::A() { B::ui->blancH2->setValue(2); } ``` B.h ``` #include <QWidget> #ifndef B_H #define B_H namespace Ui { class B; } class B { Q_OBJECT public: explicit B(QWidget *parent = 0); public: Ui::B *ui; }; #endif ``` As result of compiling I have next errors: A.cpp: In constructor 'A::A()': invalid use of incomplete type 'class Ui::B' B.h: forward declaration of 'class Ui::B' Can anybody explain why I have this errors?

Original source