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. How to create QList of 2 demension?
Forum Updated to NodeBB v4.3 + New Features

How to create QList of 2 demension?

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 9 Posters 6.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.
  • aha_1980A aha_1980

    Something like this?

    struct Bookmark {
      QString title;
      QString url;
    }
    
    void test()
    {
      QList<Bookmark> bookmarks;
      bookmarks.title = "Hello";
      bookmarks.url = "World";
    }
    
    sonichyS Offline
    sonichyS Offline
    sonichy
    wrote on last edited by
    #6

    @aha_1980 said in How to create QList of 2 demension?:

    struct

    Yes, this is it!
    Can it use method of QList such as append, remove?

    https://github.com/sonichy

    jsulmJ 1 Reply Last reply
    0
    • sonichyS sonichy

      @aha_1980 said in How to create QList of 2 demension?:

      struct

      Yes, this is it!
      Can it use method of QList such as append, remove?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #7

      @sonichy A QList is a QList, so yes you can use QList methods...

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • aha_1980A aha_1980

        Something like this?

        struct Bookmark {
          QString title;
          QString url;
        }
        
        void test()
        {
          QList<Bookmark> bookmarks;
          bookmarks.title = "Hello";
          bookmarks.url = "World";
        }
        
        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #8

        @aha_1980 A correction:

        struct Bookmark {
          QString title;
          QString url;
        }
        
        void test()
        {
          QList<Bookmark> bookmarks;
          Bookmark bookmark;
          bookmarks.append(bookmark);
          bookmarks[0].title = "Hello";
          bookmarks[0].url = "World";
        }
        

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • BjornWB Offline
          BjornWB Offline
          BjornW
          wrote on last edited by
          #9

          @jsulm said in How to create QList of 2 demension?:

          @aha_1980 A correction:

          struct Bookmark {
            QString title;
            QString url;
          }
          
          void test()
          {
            QList<Bookmark> bookmarks;
            Bookmark bookmark;
            bookmarks.append(bookmark);
            bookmarks[0].title = "Hello";
            bookmarks[0].url = "World";
          }
          

          I suppose you may also need to create some operatos for your struct, like == and perhaps >. For full functionality, that is.

          1 Reply Last reply
          0
          • aha_1980A Offline
            aha_1980A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on last edited by
            #10

            Sorry, my example was not fully correct:

            struct Bookmark {
              QString title;
              QString url;
            }
            
            void test()
            {
              QList<Bookmark> bookmarks;
              Bookmark mark;
              mark.title = "Hello";
              mark.url = "World";
              bookmarks.append(mark);
            }
            

            So yes, all QList function work here.

            Qt has to stay free or it will die.

            sonichyS 1 Reply Last reply
            1
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #11

              you can also use QList<QPair<QString,QString> > bookmarks

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              Taz742T 1 Reply Last reply
              3
              • VRoninV VRonin

                you can also use QList<QPair<QString,QString> > bookmarks

                Taz742T Offline
                Taz742T Offline
                Taz742
                wrote on last edited by
                #12

                @VRonin said in How to create QList of 2 demension?:

                QList<QPair<QString,QString> > bookmarks

                http://www.cplusplus.com/reference/utility/make_pair/

                Do what you want.

                1 Reply Last reply
                0
                • BjornWB Offline
                  BjornWB Offline
                  BjornW
                  wrote on last edited by
                  #13

                  @VRonin said in How to create QList of 2 demension?:

                  you can also use QList<QPair<QString,QString> > bookmarks

                  Using QPair is a good idea because it automagically provides operator== etc, which is useful if you want to search and sort ^_^

                  Taz742T 1 Reply Last reply
                  1
                  • BjornWB BjornW

                    @VRonin said in How to create QList of 2 demension?:

                    you can also use QList<QPair<QString,QString> > bookmarks

                    Using QPair is a good idea because it automagically provides operator== etc, which is useful if you want to search and sort ^_^

                    Taz742T Offline
                    Taz742T Offline
                    Taz742
                    wrote on last edited by
                    #14

                    @BjornW
                    Also if you using std::set<std::pair<T, T> > or std::multiset or std::priority_queue<> you dont need seperate sort function.
                    He is sorted by the first drawer.

                    Do what you want.

                    BjornWB 1 Reply Last reply
                    -1
                    • J.HilkJ Offline
                      J.HilkJ Offline
                      J.Hilk
                      Moderators
                      wrote on last edited by
                      #15

                      Wouldn't it be more convenient to use a QList<QList<QString> > or QList<QVector<QString> > ? those have an easier constructor than the QPair<T1, T2> qMakePair(const T1 &value1, const T2 &value2) path?


                      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.

                      Taz742T 1 Reply Last reply
                      0
                      • J.HilkJ J.Hilk

                        Wouldn't it be more convenient to use a QList<QList<QString> > or QList<QVector<QString> > ? those have an easier constructor than the QPair<T1, T2> qMakePair(const T1 &value1, const T2 &value2) path?

                        Taz742T Offline
                        Taz742T Offline
                        Taz742
                        wrote on last edited by
                        #16

                        @J.Hilk
                        It's not convenient for me if I need only two divisions.
                        i think std::pair<T, T> is best way if you dont forget what does it mean first and second after a while. haha

                        Do what you want.

                        L.GogsL 1 Reply Last reply
                        -1
                        • Taz742T Taz742

                          @J.Hilk
                          It's not convenient for me if I need only two divisions.
                          i think std::pair<T, T> is best way if you dont forget what does it mean first and second after a while. haha

                          L.GogsL Offline
                          L.GogsL Offline
                          L.Gogs
                          wrote on last edited by
                          #17

                          @Taz742
                          სწორი ხარ.

                          Taz742T 1 Reply Last reply
                          0
                          • L.GogsL L.Gogs

                            @Taz742
                            სწორი ხარ.

                            Taz742T Offline
                            Taz742T Offline
                            Taz742
                            wrote on last edited by Taz742
                            #18

                            @L.Gogs
                            იფ იუ დონთ ნაუ ჰაუ თუ ფლეი შათაფ ანდ ფლეი

                            Do what you want.

                            L.GogsL 1 Reply Last reply
                            -1
                            • Taz742T Taz742

                              @L.Gogs
                              იფ იუ დონთ ნაუ ჰაუ თუ ფლეი შათაფ ანდ ფლეი

                              L.GogsL Offline
                              L.GogsL Offline
                              L.Gogs
                              wrote on last edited by
                              #19

                              @Taz742
                              სოლომონ?

                              Taz742T 1 Reply Last reply
                              0
                              • L.GogsL L.Gogs

                                @Taz742
                                სოლომონ?

                                Taz742T Offline
                                Taz742T Offline
                                Taz742
                                wrote on last edited by
                                #20

                                @L.Gogs
                                ბიჩ ბლიადდდ.

                                Do what you want.

                                1 Reply Last reply
                                -1
                                • Taz742T Taz742

                                  @BjornW
                                  Also if you using std::set<std::pair<T, T> > or std::multiset or std::priority_queue<> you dont need seperate sort function.
                                  He is sorted by the first drawer.

                                  BjornWB Offline
                                  BjornWB Offline
                                  BjornW
                                  wrote on last edited by
                                  #21

                                  @Taz742 I was compering to the alternative using a struct. Also set and list are different, he didn't mention anything about unique values.

                                  1 Reply Last reply
                                  0
                                  • aha_1980A aha_1980

                                    Sorry, my example was not fully correct:

                                    struct Bookmark {
                                      QString title;
                                      QString url;
                                    }
                                    
                                    void test()
                                    {
                                      QList<Bookmark> bookmarks;
                                      Bookmark mark;
                                      mark.title = "Hello";
                                      mark.url = "World";
                                      bookmarks.append(mark);
                                    }
                                    

                                    So yes, all QList function work here.

                                    sonichyS Offline
                                    sonichyS Offline
                                    sonichy
                                    wrote on last edited by sonichy
                                    #22

                                    @aha_1980
                                    Thank you for your resolution, I have finished history record of QWebView with 3 members!
                                    https://github.com/sonichy/Qt_HTYBrowser

                                    // define
                                    struct History {
                                        QString stime;
                                        QString title;
                                        QString surl;
                                    };
                                    
                                    // append
                                    QList<History> historys;
                                    History history;
                                    history.stime = strlist.at(0);
                                    history.title = strlist.at(1);
                                    history.surl = strlist.at(2);
                                    historys.append(history);
                                    
                                    // use
                                    historys.at(i).stime
                                    historys.at(i).surl
                                    historys.at(i).title

                                    https://github.com/sonichy

                                    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