Fredy Solis
Fredy Solis

Reputation: 1

qt multiple instances of custom widget fail to excecute their slots

I'm developing a gui in qt5.7 with qtcreator. I made a widget that contains check-boxes and combo-boxes to represent the same number. I use the signal toggled() to set the new index in the combobox. Then I do the same with the currentIndexChanged() signal to set the new states for checkboxes. This works fine.

My problem begins when i use 4 instances of my custom widget. When I select a new value for combobox in instance[0] its checkboxes doesnt change, instead, the values of instance 3 change.

Here is the part of code where I use connect statement in my custom widget.

QCheckBox* tri_st[NUM_TRIST_BUFF];

Qt_adc_delay::Qt_adc_delay(QWidget *parent) :
QWidget(parent),
ui (new Ui::Qt_adc_delay)
{
ui->setupUi(this);
int i = 0;           
...
Assign the checkboxes in widget to tri_st[]
...
for(i=0;i<NUM_TRIST_BUFF;i++)
    connect(tri_st[i],SIGNAL(toggled(bool)),this,SLOT(tri_state_checks_Changed(void)));

I will try to use disconnect() and connect() again in my top widget to make it work but. There is an easy way to do it?

pd: Here is part of my ui_widget.h (generated for uic, qtcreator)

class Ui_Widget
{
public:
Qt_adc_delay *widget;
Qt_adc_delay *widget_2;

void setupUi(QWidget *Widget)
{
    if (Widget->objectName().isEmpty())
        Widget->setObjectName(QStringLiteral("Widget"));
    Widget->resize(500, 400);
    widget = new Qt_adc_delay(Widget);
    widget->setObjectName(QStringLiteral("widget"));
    widget->setGeometry(QRect(10, 10, 205, 400));
    widget_2 = new Qt_adc_delay(Widget);
    widget_2->setObjectName(QStringLiteral("widget_2"));
    widget_2->setGeometry(QRect(220, 10, 205, 400));

    retranslateUi(Widget);

    QMetaObject::connectSlotsByName(Widget);
} // setupUi

Upvotes: 0

Views: 52

Answers (1)

SGaist
SGaist

Reputation: 928

You shouldn't modify Ui_Widget, it's a generated file that will be overwritten. Take a look at Using a Designer UI File in Your Application for a description of the various technique you can use to customise a designer based widget.

Then tri_st that's a static array of pointer, why make it static ? If it's for the sake of making a simple loop for the connect statement then just build a QVector<QComboBox*> while creating your combo boxes and then use that for the connection loop.

Upvotes: 0

Related Questions