Solved How to create QList of 2 demension?
-
@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? -
@sonichy A QList is a QList, so yes you can use QList methods...
-
@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"; }
-
@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.
-
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.
-
you can also use
QList<QPair<QString,QString> > bookmarks
-
@VRonin said in How to create QList of 2 demension?:
QList<QPair<QString,QString> > bookmarks
-
@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 ^_^
-
@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. -
Wouldn't it be more convenient to use a
QList<QList<QString> >
orQList<QVector<QString> >
? those have an easier constructor than theQPair<T1, T2> qMakePair(const T1 &value1, const T2 &value2)
path? -
@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 -
@Taz742
სწორი ხარ. -
@L.Gogs
იფ იუ დონთ ნაუ ჰაუ თუ ფლეი შათაფ ანდ ფლეი -
@Taz742
სოლომონ? -
@L.Gogs
ბიჩ ბლიადდდ. -
@Taz742 I was compering to the alternative using a struct. Also set and list are different, he didn't mention anything about unique values.
-
@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