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?
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.
As the error says, there is no definition of Ui::B
available, only the declaration in B.h
; and you can't write code that accesses members of a class unless the class has been defined.
You need to include whichever header defines Ui::B
; or, perhaps, give B
a member function to do whatever A
needs doing, rather than furtling with B
's members directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With