QLineEdit editingFinished twice when changing focus?



  • I know this has been covered a few times before, for instance in this thread....
    http://qt-project.org/forums/viewthread/39775
    but these appear to refer to cases where a message box is used in the slot handler.

    I am a bit stuck as I have it even without any code in the slot handler so stuff like blockSignals() can't solve it.

    For a test, I have an array of QLineEdit which use a signalMapper to connect the editingFinished() signals to a single slot. The signalMapper passes the array index so I can see where the signal came from.
    eg:
    @testenter::testenter(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::testenter)
    {
    // setup the UI according to the .h file
    ui->setupUi(this);

    signalMapper = new QSignalMapper(this);
    
    // init the labels and edit boxes
    for (int i = 0; i < 10; i++)
    {
        pm_label[i] = new QLabel(ui->scrollArea);
        QString text = QString("Number %1").arg(i);
        pm_label[i]->setText(text);
        pm_label[i]->setGeometry(10,20+i*30, 50, 20);
        pm_label[i]->show();
    
        pm_editBox[i] = new QLineEdit(ui->scrollArea);
        pm_editBox[i]->setGeometry(80,20+i*30, 50, 20);
        pm_editBox[i]->show();
    
        signalMapper->setMapping(pm_editBox[i], int(i));
        connect(pm_editBox[i], SIGNAL(editingFinished()), signalMapper, SLOT(map()));
    }
    connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(data_entry(int)));
    

    }

    void testenter::data_entry(int entry)
    {
    //dummy
    }
    @
    When run in the debugger, if I enter data into one box then either hit return or select another box with the mouse (ie change focus) , then it calls data_entry twice, the first time with index of the box that is losing focus and the 2nd time with the box which gets the focus.

    Am I missing something? I expected editingFinished to be the best signal to use if I need to act after data is entered (by either return, tab or mouse click) but it doesn't appear I can use it this way.

    btw. I've been programming off and on for about 30 years but only recently on C++/Qt so be gentle if I am being stupid ;)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.