Results 1 to 4 of 4

Thread: Why setCurrentText() in QComboBox is deprecated?

  1. #1
    Join Date
    Mar 2007
    Posts
    58
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Why setCurrentText() in QComboBox is deprecated?

    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:

    Qt Code:
    1. inline QT3_SUPPORT void setCurrentText(const QString& text) {
    2. int i = findText(text);
    3. if (i != -1)
    4. setCurrentIndex(i);
    5. else if (isEditable())
    6. setEditText(text);
    7. else
    8. setItemText(currentIndex(), text);
    9. }
    To copy to clipboard, switch view to plain text mode 

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

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

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why setCurrentText() in QComboBox is deprecated?

    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

  3. #3
    Join Date
    Mar 2007
    Posts
    58
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why setCurrentText() in QComboBox is deprecated?

    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".

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why setCurrentText() in QComboBox is deprecated?

    You can do that.
    But you don't have to replace all combos. Just promote them to custom widgets.

    Regards

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.