简体   繁体   中英

How i can sort a list item by alphabetical order with QSortFilterProxyModel?

Hi i have set the QSortFilterProxyModel property in this mode

int main(int argc, char *argv[])
{

    ....

    ProgramFilterProxyModel programFPModel{};
    programFPModel.setSourceModel(&pm);
    engine.rootContext()->setContextProperty("programFPModel", &programFPModel);

   ....

}

ProgramFilterProxyModel::ProgramFilterProxyModel(QObject *parent) :
    QSortFilterProxyModel(parent), m_stringaRicerca(""),
    m_programListCurrIndex(0)
{
    setSortRole(ProgramModel::NameQml);
    setDynamicSortFilter(true);
    sort(0);
    setSortLocaleAware(true);

}

....

When i execute my application on Ubuntu the item are correctly sort by alphabetical order because i have set isSortLocaleAware property on true, instead if i try to execute my application on embedded systems with buildroot OS(IMX6 microcontroller) the items aren't sort by alphabetical order.

If i try to print with:

qDebug()<< QLocale::system().language()

the locale of my buildroot OS the output is "C", instead on ubuntu is italian maybe is this the problem?

How i can sort the items by name and sort by alphabetical order without setSortLocaleAware(true)?

The order list that i want is the same sort order of a file list for example in ubuntu.

Example:

  • a.txt
  • A.txt
  • à.txt
  • b.txt
  • B.txt

You may set your default locale (as soon as possible in your main())

QLocale::setDefault(QLocale(QLocale::Italian));

The above line is just an example. You should set a variable locale, depending on the user preferences, etc.

Or you can overide the protected method bool QSortFilterProxyModel::lessThan() and compare the items as you wish. See the Custom Sort/Filter Model Example .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM