How to create QList of 2 demension?
-
I want to design bookmark function of QWebView by read and write file like this:
title1,website1
title2,website2
...
Can QList use as 2 demension? -
Something like this?
struct Bookmark { QString title; QString url; } void test() { QList<Bookmark> bookmarks; bookmarks.title = "Hello"; bookmarks.url = "World"; }
-
Something like this?
struct Bookmark { QString title; QString url; } void test() { QList<Bookmark> bookmarks; bookmarks.title = "Hello"; bookmarks.url = "World"; }
-
@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? -
Something like this?
struct Bookmark { QString title; QString url; } void test() { QList<Bookmark> bookmarks; bookmarks.title = "Hello"; bookmarks.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.
-
@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 ^_^
-
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? -
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