Important: Please read the Qt Code of Conduct -

Slicing a QList

  • When in python I can do list[0:3]

    Then how can I do the same thing in C++?

    I know that QList has a function called mid(int pos, int length) but that is nothing like list slicing since I can't specify an end point, only the starting point

    Right now I'm using a simple for loop for this but it seems to slow down my code

  • Are you a programmer? A programmer would know that the containers have several methods that return the length() of the container, thus allowing the operation you desire. Granted, you're never going to get the niceties that you get with python element acces such as list[0:-2] but for getting ranges you can easily accomplish using mid() and some math based on length() or count()

Log in to reply