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. Qt 6.5 : how to convert QList to std::vector ?
Forum Updated to NodeBB v4.3 + New Features

Qt 6.5 : how to convert QList to std::vector ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 2.6k Views 2 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.
  • D Offline
    D Offline
    dpcrd
    wrote on last edited by dpcrd
    #1

    Hello,

    I am porting a Qt5 code that uses a library that manipulates std::vector objects. In Qt5, I would convert a QList to a std::vector like this :

    QList<double> myL;
    std::vector<double> myV = myL.toVector().toStdVector()
    

    But QList::toVector() has become obsolete, and toStdVector() has disappeared. What is the new best way to do this conversion in Qt6.5 ?

    sierdzioS Christian EhrlicherC 2 Replies Last reply
    0
    • D dpcrd

      Hello,

      I am porting a Qt5 code that uses a library that manipulates std::vector objects. In Qt5, I would convert a QList to a std::vector like this :

      QList<double> myL;
      std::vector<double> myV = myL.toVector().toStdVector()
      

      But QList::toVector() has become obsolete, and toStdVector() has disappeared. What is the new best way to do this conversion in Qt6.5 ?

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      I guess something like this should work:

      std::vector<double> myV(myL.constBegin(), myL.constEnd());
      

      (Z(:^

      1 Reply Last reply
      1
      • D dpcrd

        Hello,

        I am porting a Qt5 code that uses a library that manipulates std::vector objects. In Qt5, I would convert a QList to a std::vector like this :

        QList<double> myL;
        std::vector<double> myV = myL.toVector().toStdVector()
        

        But QList::toVector() has become obsolete, and toStdVector() has disappeared. What is the new best way to do this conversion in Qt6.5 ?

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Since QList and QVector is the same, toVector() is not needed anymore. And for the construction of std::vector you can use the range constructor:

        std::vector<double> v(l. constBegin(), l.constEnd());

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        2

        • Login

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