Get previous value of QComboBox, which is in a QTableWidget, when the value is changed

How about creating your own, derived QComboBox class, something along the lines of:

class MyComboBox : public QComboBox
{
  Q_OBJECT
private:
  QString _oldText;
public:
  MyComboBox(QWidget *parent=0) : QComboBox(parent), _oldText() 
  {
    connect(this,SIGNAL(editTextChanged(const QString&)), this, 
        SLOT(myTextChangedSlot(const QString&)));
    connect(this,SIGNAL(currentIndexChanged(const QString&)), this, 
        SLOT(myTextChangedSlot(const QString&)));
  }
private slots:
  myTextChangedSlot(const QString &newText)
  {
    emit myTextChangedSignal(_oldText, newText);
    _oldText = newText;
  }
signals:
  myTextChangedSignal(const QString &oldText, const QString &newText);  
};

And then just connect to myTextChangedSignal instead, which now additionally provides the old combo box text.

I hope that helps.


A bit late but I had the same problem and solved in this way:

class CComboBox : public QComboBox
{
   Q_OBJECT

   public:
      CComboBox(QWidget *parent = 0) : QComboBox(parent) {}


      QString GetPreviousText() { return m_PreviousText; }

   protected:
      void mousePressEvent(QMouseEvent *e)
      { 
         m_PreviousText = this->currentText(); 
         QComboBox::mousePressEvent(e); 
      }

   private:
      QString m_PreviousText;
};