Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Slicing a QList
Qt 6.12 LTS is out! See what's new in the release blog

Slicing a QList

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.5k 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()

      The dystopian literature that served as a warning in my youth has become an instruction manual in my elder years.

      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
      • Unsolved