Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Slicing a QList
Forum Updated to NodeBB v4.3 + New Features

Slicing a QList

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 996 Views 1 Watching
  • 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 Offline
    F Offline
    Fuchsiaff
    wrote on last edited by
    #1

    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
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      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
      4

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved