Qt-interest Archive, July 2007
On roaming stl-style iterators
Message 1 in thread
Hi all, I've been battling all the day with this fact which seems to
me quite a nonsense but I'm asking you for clarifications. I have a
QList of int, so
QList<int> L;
L << 10 << 20 << 30 << 40 << 50;
Now I need to browse the list and make some work on it (such as
insertions, removals, swaps...) so I just declare ad initialize two
stl-style iterators like the following:
QList<int>::Iterator iL, jL;
iL = L.begin();
jL = iL + 1;
and now comes the tricky part. As I have my iterators poiting around
the list, say iL is poiting position 0 and jL is pointing position 1,
I do something like
jL = L.erase(jL);
and surprise! iL is now pointing -1 and jL is correctly pointing 1.
Let's do somthing more dangerous:
L.move(jL - L.begin(), 0) // Move L[1] in front of the list
and here comes the pain: iL is still pointing -1 and jL is still
(correctly, I guess) pointing 1.
The real issue that is bothering me since this morning is: why the
heck that QList<T>::erase(QList<T>::Iterator) have to displace any
other iterator pointing around the same list? Is this insane or is it
just me?
I'm trying this on Qt 4.3 on Linux.
Greets
--
[ signature omitted ]
Message 2 in thread
Am Donnerstag, 5. Juli 2007 22:53 schrieb Andrea Franceschini:
> Hi all, I've been battling all the day with this fact which seems to
> me quite a nonsense but I'm asking you for clarifications. I have a
> QList of int, so
>
> QList<int> L;
> L << 10 << 20 << 30 << 40 << 50;
>
> Now I need to browse the list and make some work on it (such as
> insertions, removals, swaps...) so I just declare ad initialize two
> stl-style iterators like the following:
>
> QList<int>::Iterator iL, jL;
> iL = L.begin();
> jL = iL + 1;
>
> and now comes the tricky part. As I have my iterators poiting around
> the list, say iL is poiting position 0 and jL is pointing position 1,
> I do something like
>
> jL = L.erase(jL);
>
> and surprise! iL is now pointing -1 and jL is correctly pointing 1.
> Let's do somthing more dangerous:
>
> L.move(jL - L.begin(), 0) // Move L[1] in front of the list
>
> and here comes the pain: iL is still pointing -1 and jL is still
> (correctly, I guess) pointing 1.
>
> The real issue that is bothering me since this morning is: why the
> heck that QList<T>::erase(QList<T>::Iterator) have to displace any
> other iterator pointing around the same list? Is this insane or is it
> just me?
>
> I'm trying this on Qt 4.3 on Linux.
>
From Qt Doc:
Internally, QList<T> is represented as an array of pointers to items.
This possibly explains your pain. since the array needs to be reorganized when
you erase something from the begin or end.
Try QLinkedList<T>. This might be much better for your purpose, or use a real
stl implementation.
> Greets
--
[ signature omitted ]
Message 3 in thread
From the QList doc:
"Multiple iterators can be used on the same list. However, be aware that
any non-const function call performed on the QList will render all
existing iterators undefined. If you need to keep iterators over a long
period of time, we recommend that you use QLinkedList rather than
QList."
Cheers,
Peter
> -----Original Message-----
> From: Andrea Franceschini [mailto:therealmorpheu5@xxxxxxxxx]
> Sent: Thursday, July 05, 2007 10:54 PM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: On roaming stl-style iterators
>
> Hi all, I've been battling all the day with this fact which seems to
> me quite a nonsense but I'm asking you for clarifications. I have a
> QList of int, so
>
> QList<int> L;
> L << 10 << 20 << 30 << 40 << 50;
>
> Now I need to browse the list and make some work on it (such as
> insertions, removals, swaps...) so I just declare ad initialize two
> stl-style iterators like the following:
>
> QList<int>::Iterator iL, jL;
> iL = L.begin();
> jL = iL + 1;
>
> and now comes the tricky part. As I have my iterators poiting around
> the list, say iL is poiting position 0 and jL is pointing position 1,
> I do something like
>
> jL = L.erase(jL);
>
> and surprise! iL is now pointing -1 and jL is correctly pointing 1.
> Let's do somthing more dangerous:
>
> L.move(jL - L.begin(), 0) // Move L[1] in front of the list
>
> and here comes the pain: iL is still pointing -1 and jL is still
> (correctly, I guess) pointing 1.
>
> The real issue that is bothering me since this morning is: why the
> heck that QList<T>::erase(QList<T>::Iterator) have to displace any
> other iterator pointing around the same list? Is this insane or is it
> just me?
>
> I'm trying this on Qt 4.3 on Linux.
>
> Greets
>
> --
> Andrea Franceschini
--
[ signature omitted ]
Message 4 in thread
Hi,
I have here a minor problem. Perhaps someone could point me in the right direction.
I have a QComboBox, which I pass a custom made QAbstractListMode derived model.
I implemented data() and count(). Everything looks good so far, the QComboBox is
filled with the model's text data. However, the findText method always returns -1,
even if the string is in the box.
I can 'iterate' through the box and compare my string against itemText(i). It works,
but is clumsy. I'd rather use the findText method.
Any ideas?
Guido
--
[ signature omitted ]
Message 5 in thread
Hi. I'm having some problems with QGraphicsItemGroup (on Mac, Qt 4.3)
and am hoping for some help. In the simplest-case example below, I
create two QGraphicsRectItems and put them in a group. When I try to
click and drag the group, it works if I click BETWEEN the items, but
not ON them.
Am I missing some flag that will allow me to click anywhere on the
group? (In my real app, which is considerably more complicated, when
I start to drag an item then entire group goes zooming off the screen
in the -X, -Y direction.)
Thanks!
------
QApplication app(argc, argv);
QGraphicsScene scene(0, 0, 400, 300);
QGraphicsView view(&scene);
view.show();
QGraphicsRectItem* rect1 = scene.addRect(QRectF(10,10,30,30));
QGraphicsRectItem* rect2 = scene.addRect(QRectF(50,10,30,30));
rect1->setFlags(QGraphicsItem::ItemIsSelectable |
QGraphicsItem::ItemIsMovable);
rect2->setFlags(QGraphicsItem::ItemIsSelectable |
QGraphicsItem::ItemIsMovable);
rect1->setSelected(true);
rect2->setSelected(true);
QGraphicsItemGroup *group = scene.createItemGroup(scene.selectedItems
());
group->setFlags(QGraphicsItem::ItemIsSelectable |
QGraphicsItem::ItemIsMovable);
return app.exec();
--
[ signature omitted ]
Message 6 in thread
I tries a stripped down version of my program. If I use the database
(sqlite) only for the QTableView everything works fine. In my real word
problem I have a QTableView, which should show a certain view and
plenty of other lists and comboboxes, which are filled with other
aspects of the same database. I don't know why, but this seems to be a
problem. At program start I open the database and keep the connection
permanently open. I tried to close and reopen it before I set the query
for the table view, but no difference.
Anyone an idea where the problem is and how to avoid it?
Guido
--
[ signature omitted ]
Message 7 in thread
2007/7/6, Peter Prade <prade@xxxxxxxxxxx>:
> From the QList doc:
Thank you both. I really didn't read the docs very carefully as I
trusted QList to behave the way which seemed to me the most logical.
Anyway, my collegues managed to find a solution even before I could
write to the ML :)
Cheers
--
[ signature omitted ]