hi , all.
i use Qtcreator creator Qt designer ui and class .
i try use the ui pointer in my child class.
parent class code , in widget.h :
namespace Ui {
class Widget;
}
{
Q_OBJECT
public:
explicit Widget
(QWidget *parent
= 0);
~Widget();
Ui::Widget *ui; //ui is public
private slots:
void on_pushButton_clicked();
};
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
Ui::Widget *ui; //ui is public
private slots:
void on_pushButton_clicked();
};
To copy to clipboard, switch view to plain text mode
child class code , in widget_child.h :
class Widget_Child : public Widget
{
public:
WidgetB_Child
(QWidget * parent
= 0);
};
class Widget_Child : public Widget
{
public:
WidgetB_Child(QWidget * parent = 0);
};
To copy to clipboard, switch view to plain text mode
child class code , in widget_child.cpp :
Widget_Child
::Widget_Child(QWidget * parent
) : Widget(parent)
{
ui->pushButton->setText("Widget_Child");
}
Widget_Child::Widget_Child(QWidget * parent) :
Widget(parent)
{
ui->pushButton->setText("Widget_Child");
}
To copy to clipboard, switch view to plain text mode
a compiler error:
E:\QtCode\Test\widget_child.cpp:6: error: request for member 'pushButton' in '((Widget_Child*)this)->Widget_Child::<anonymous>.Widget::ui', which is of pointer type 'Ui::Widget*' (maybe you meant to use '->' ?)
ui.pushButton->setText("Widget_Child");
^
i use QtCreator 4.0 Qt5.4.2 , Win7 64bit
Added after 18 minutes:
i add #include<ui_widget.h> is no problem.
but , I don't know public:Ui::Widget *ui; whether the effect was encapsulation ?
Bookmarks