Immutable QList



  • Hello everyone,
    I wonder if there is a way to get immutable list from regular QList. A fail-safe list is better but I would appreciate any suggestions.
    Thanks in advance)


  • Qt Champions 2016

    @diredko
    Hello.

    I wonder if there is a way to get immutable list from regular QList.

    Is that what you're after?

    QList<int> mutableList;
    const QList<int> & immutableList = mutableList;
    

    A fail-safe list is better

    What do you mean by fail-safe list?



  • Thanks for your reply)
    I'd like to provide some clarifications:
    By saying "immutable" I meant that after some elements are added to this list, its content cannot be modified - add, remove and insert operations are prohibited or just won't take any effect.
    By saying "fails-safe" I meant that whenever such an operation is called on immutable list no application failure will arise and no exception will be thrown.


  • Qt Champions 2016

    @diredko
    Hello,
    Both your requirements are met by the const keyword in C++. A const object can't be modified and prevents you from calling non-const functions. What is it that you're trying to achieve?

    Kind regards.



  • Thanks for your reply) This is exactly what I needed)


Log in to reply
 

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