Reputation: 109
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?
Upvotes: 6
Views: 26411
Reputation: 11
Actually I met this problem when I've changed the name of 'MainWindow' to 'LoginWindow' after the whole app is established.This can't be useful for everyone but change the name of it to the original one(which you filled in when start the project) can work for me. Still don't know about .ui files of Qt hoping anyone can explain this~
Upvotes: 1
Reputation: 51
In Qt Creator, open the dialog form. Select the dialog panel and on the right be sure that the Object Name is B.
That will let the Qt build system know that your object is a UI object. Without this, your program only knows your panel as an object name Dialog.
Upvotes: 5
Reputation: 183
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.
Upvotes: 15
Reputation: 254451
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.
Upvotes: 11