I have a Custom Container Widget (we’ll call it WidgetA) which consists of some number of widgets, as well as a container that is exposed to Qt Designer using a QDesignerContainerExtension. I then have another widget (WidgetB) which extends WidgetA, adding a number of widgets to the container in WidgetA. Both widgets have a .ui form file associated with them.
This configuration works well for my purposes with one exception. Qt’s connectSlotsByName function, which runs within the setupUI function of both classes, is causing the widgets of Widget A to be connected to their slots twice. My code looks something like this:
// WidgetA.h
namespace Ui {
class WidgetA;
}
class WidgetA : public QWidget
{
Q_OBJECT
public:
explicit WidgetA( QWidget* parent = 0 ) :
QWidget( parent ),
ui( new Ui::WidgetA )
{
ui->setupUi( this ); // <-- Connects widgets in WidgetA.
}
// ...
private:
Ui::WidgetA* ui;
}
// ...
// WidgetB.h
namespace Ui {
class WidgetB;
}
class WidgetB : public WidgetA
{
Q_OBJECT
public:
explicit WidgetB( QWidget* parent = 0 ) :
WidgetA( parent ), // <-- WidgetA’s constructor, calls setupUi resulting in WidgetA’s widgets being connected.
ui( new Ui::WidgetB )
{
ui->setupUi( this ); // <-- Connects widgets in WidgetA and WidgetB, resulting in duplicate connection of WidgetA’s widgets.
}
// ...
private:
ui::WidgetB* ui;
}
I’m aware of the Qt:: UniqueConnection flag, but because the ui’s header class is generated automatically I have no control over the nature of the connections. How can avoid this double connection?