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. Is it possible to make a QList of tuples?
Forum Updated to NodeBB v4.3 + New Features

Is it possible to make a QList of tuples?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 5 Posters 2.1k 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.
  • A Offline
    A Offline
    abanksdev
    wrote on last edited by
    #1

    Something like

    QList<std::tuple<int,int>> mapCoordinatesList = {(10,10), (10,30), (40,70), (120,80), (190,60), (220,30), (220,0)};
     
    
    

    That can be accessed with

    xVal = mapCoordinatesList[0][0]
    
    raven-worxR 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Why not use QVector<QPoint> instead and what does not work in your example?

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

      J.HilkJ A 2 Replies Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        Why not use QVector<QPoint> instead and what does not work in your example?

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @Christian-Ehrlicher said in Is it possible to make a QList of tuples?:

        Why not use QVector<QPoint> instead and what does not work in your example?

        My guess is, the initalizer list does not auto convert to std::tuple? Because this one works

        QList<std::tuple<int,int>> mapCoordinatesList = {std::tuple<int,int>(10,10), std::tuple<int,int>(10,30), std::tuple<int,int>(40,70), std::tuple<int,int>(120,80), std::tuple<int,int>(190,60), std::tuple<int,int>(220,30), std::tuple<int,int>(220,0)};
        

        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        1
        • A abanksdev

          Something like

          QList<std::tuple<int,int>> mapCoordinatesList = {(10,10), (10,30), (40,70), (120,80), (190,60), (220,30), (220,0)};
           
          
          

          That can be accessed with

          xVal = mapCoordinatesList[0][0]
          
          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @abanksdev
          Something like this should also work:

          struct MyTuple {
             int x;
             int y;
          };
          QList<MyTuple> mapCoordinatesList = {
              {10,10}, {10,30}, {40,70}, {120,80}, ...
          };
          

          (untested)

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          1
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @J.Hilk said in Is it possible to make a QList of tuples?:

            My guess is, the initalizer list does not auto convert to std::tuple?

            Correct, there are also a lot of answers in the net why it does not work. :)

            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
            0
            • Christian EhrlicherC Christian Ehrlicher

              Why not use QVector<QPoint> instead and what does not work in your example?

              A Offline
              A Offline
              abanksdev
              wrote on last edited by
              #6

              @Christian-Ehrlicher
              I get the following error

              /Users/banks.audrey/altitudeStatusFrame/main.cpp:6: error: no matching constructor for initialization of 'QList<std::tuple<int, int> >'
                  QList<std::tuple<int,int>> mapCoordinatesList = {(10,10), (10,30), (40,70), (120,80), (190,60), (220,30), (220,0)};
                                             ^                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              

              Let me try what @J-Hilk suggested

              but also QVectory<QPoint> would work, but im getting the following error:

              /Users/banks.audrey/altitudeStatusFrame/main.cpp:11: error: implicit instantiation of undefined template 'QVector<QPoint>'
                  QVector<QPoint> statusFrameCoordinatesList(7);
                                  ^
              
              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi,

                Use: QList<std::tuple<int,int>> mapCoordinatesList = {{10,10}, {10,30}, {40,70}, {120,80}, {190,60}, {220,30}, {220,0}};

                As for your second error, I can't reproduce it.

                What compiler are you using ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1
                • A Offline
                  A Offline
                  abanksdev
                  wrote on last edited by
                  #8

                  I used @raven-worx's method and got it working, thanks!

                  1 Reply Last reply
                  0

                  • Login

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