Delete a layer in run time

  • Hi, i have this code:
    QWidget *oneLineWidget = new QWidget(this);

        QHBoxLayout *oneLineWidgetLayout = new QHBoxLayout();
        { //added these brackets just for the ease of reading.
            QLabel *labFirst = new QLabel(tr("ارسال پیام خطا "), oneLineWidget);
            QPushButton *Btn_Errormsg = new QPushButton(tr("ویرایش"), oneLineWidget);
            QLabel *labSecond = new QLabel(tr("در صورت دریافت سیگنال از پایانه "), oneLineWidget);
            QLineEdit *LineEdit = new QLineEdit("", oneLineWidget);
            QLabel *labSecond1 = new QLabel(tr("و سطح ولتاژ "), oneLineWidget);
            QPushButton *Btn_Voltaj = new QPushButton(tr("ویرایش "), oneLineWidget);
            QPushButton *Btn_Delete = new QPushButton(tr("delete"), oneLineWidget);
            signalMapper->setMapping(Btn_Delete, oneLineWidget);
            Voltaj->setMapping(Btn_Voltaj, oneLineWidget);
            connect(Btn_Delete, SIGNAL(clicked()), signalMapper, SLOT(map()));
            connect(signalMapper, SIGNAL(mapped(QWidget*)),this,SLOT(AddAnalog(QWidget*)));
            connect(Btn_Voltaj, SIGNAL(clicked()), signalMapper, SLOT(map()));
            connect(Voltaj, SIGNAL(mapped(QObject*)),this,SLOT(Btn_Voltaj_Click(QWidget*)));

    this code is in a button click slot i.e when i click on a button this code has been executed. and a line of widget(button, labels, line edit) are added to page.

    i want when i click on delete button that line which clicked on that deleted. i can't wrote this code in delete button click slot because the lines are dynamically added and i can't detect button is from which line. how can i do that?
    any idea?

  • Lifetime Qt Champion


    Since you are using a signalMapper and that you are mapping your oneLineWidget with the deleteBtn, why don't you use one of the "mapping" functions from QSignalMapper to retrieve the widget ?

  • Moderators

    you "already asked that question": previously and marked it as solved!
    Why do you reopen another thread?

  • yes your right. but problem is that when i add three layer(i.e three time this code is executed) when i click on delete button @AddAnalog(QWidget*)@ is executed three time instead of one time.if layer is more this function is execute same time and this is a problem i want to know the problem.

Log in to reply