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. A strange problem with QList and QVector
Forum Updated to NodeBB v4.3 + New Features

A strange problem with QList and QVector

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

    Hi,

    I am coming across a strange issue where my aim is to convert a QList<double> to std::vector<double>. This is to test a C++ code which I am trying to integrate with a Qt based GUI, altho I don't like this conversion as it it quite inefficient. Right now this is for testing purposes.

    Anyways:

    This is the problem:

        QVector<double> _temp1 =m_numerator.toVector();
        QVector<double> _temp2 =m_denominator.toVector();
        std::vector<double> _temp11 = _temp1.toStdVector();//  No member named 'toStdVector' in List<double>'
        std::vector<double> _temp21 = _temp2.toStdVector();// No member named 'toStdVector' in List<double>'
    
    M 1 Reply Last reply
    0
    • H HFT_developer

      Hi,

      I am coming across a strange issue where my aim is to convert a QList<double> to std::vector<double>. This is to test a C++ code which I am trying to integrate with a Qt based GUI, altho I don't like this conversion as it it quite inefficient. Right now this is for testing purposes.

      Anyways:

      This is the problem:

          QVector<double> _temp1 =m_numerator.toVector();
          QVector<double> _temp2 =m_denominator.toVector();
          std::vector<double> _temp11 = _temp1.toStdVector();//  No member named 'toStdVector' in List<double>'
          std::vector<double> _temp21 = _temp2.toStdVector();// No member named 'toStdVector' in List<double>'
      
      M Offline
      M Offline
      mpergand
      wrote on last edited by mpergand
      #2

      @HFT_developer
      There's something wrong somewhere, because _tempX are QVectors not QLists !
      Try to clean/rebuild your project.

      I tried this with no issue:

      QList<double> l={1,22,-1,.5};
      QVector<double> _temp1 =l.toVector();
      std::vector<double> _temp11 = _temp1.toStdVector();
      
      Chris KawaC 1 Reply Last reply
      1
      • M mpergand

        @HFT_developer
        There's something wrong somewhere, because _tempX are QVectors not QLists !
        Try to clean/rebuild your project.

        I tried this with no issue:

        QList<double> l={1,22,-1,.5};
        QVector<double> _temp1 =l.toVector();
        std::vector<double> _temp11 = _temp1.toStdVector();
        
        Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by Chris Kawa
        #3

        This would work in Qt5 but not Qt6.

        QVector and QList were unified in Qt6 and QVector is now just an alias for QList, so the message is a bit misleading but correct - there's no direct conversion to std vector.

        In Qt6 you can convert it like this:

        std::vector<double> _temp11 {_temp1.begin(), _temp1.end()};
        

        Btw. if you want to avoid the copy maybe you could use std::span on the non-Qt side of the code? It's a wrapper over external data and you can use it just like a vector, but it doesn't copy the elements. You would create it very cheaply like this:

        std::span<double> _temp11 {_temp1};
        
        1 Reply Last reply
        1

        • Login

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