Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved Slicing a QList

    General and Desktop
    2
    2
    556
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F
      Fuchsiaff last edited by

      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

      1 Reply Last reply Reply Quote 0
      • Kent-Dorfman
        Kent-Dorfman last edited by

        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()

        1 Reply Last reply Reply Quote 3
        • First post
          Last post