PDA

View Full Version : Why setCurrentText() in QComboBox is deprecated?



Pepe
12th August 2007, 00:01
In Qt 4 setCurrentText ( const QString & text ) is deprecated. The docs say that I should use setItemText() instead. But I'm afraid setItemText() is not completely equivalent to setCurrentText().

In editable comboboxes it was very useful to me. I just passed the text and if there was already an item with that text, it was automatically selected. Otherwise the text appeared to be edited.

But now setItemText() is only to change existing items. setEditText() is quite similar but it doesn't select an existing item if it matches with the text.

So I don't understand why setCurrentText() has been deprecated if there's no equivalent. In fact, this is the implementation that appears in qcombobox.h:



inline QT3_SUPPORT void setCurrentText(const QString& text) {
int i = findText(text);
if (i != -1)
setCurrentIndex(i);
else if (isEditable())
setEditText(text);
else
setItemText(currentIndex(), text);
}


And if setCurrentText() is deprecated... why currentText() is not?

So, the question, is there an easy way to replace setCurrentText() in Qt 4?

marcel
12th August 2007, 00:06
No, there isn't.
Probably they wanted to split that functionality in smaller pieces.

If you want exactly that behavior and don't want to use a deprecated function, then use its implementation(as you showed it).

There should be no problem since the implementation uses QT4 API functions.

Regards

Pepe
12th August 2007, 02:41
The problem is that I used setCurrentText() all around, I have a lot of them.

I guess I will have to subclass QComboBox just to add that function (and maybe insertStringList() as insertItems() is not completely compatible), and then replace all comboboxes in the ui files...

I also don't understand why they renamed QRegExp::search() to QRegExp::indexIn(). In this case they are the same, but I find the name "search" more intuitive than "indexIn".

marcel
12th August 2007, 02:43
You can do that.
But you don't have to replace all combos. Just promote them to custom widgets.

Regards