Dear All:
I use QPair in QVector when developing .
But there's some problem.
here is text example:
Code:
Is there any suggestion for me if I would like to copy from one vector to another ??
Thank you~~
Printable View
Dear All:
I use QPair in QVector when developing .
But there's some problem.
here is text example:
Code:
Is there any suggestion for me if I would like to copy from one vector to another ??
Thank you~~
What exact error are you getting?
qCopy assumes that the target elements allready exist and then overwrites them.
So this example must be:
Code:
void test() { QVector< QPair< int , QString > > first; for(int iIdx = 0; iIdx <5 ; ++iIdx ) qCopy(first.begin(), first.end(), second.begin()); }
Maybe this would be better:
Because it can share data until a write operation is made on either vector.
Dear wysota:
There's a exception error at run time~~
And it broke at QBasicAtomicInt::deref()...
Dear seneca:
In my program, all I need to do is copy member to another member,
It means I have to use qCopy rather than constructor, does it ??
thank you~~
Using the copy constructor will have the same effect in practise, however the data stay shared as long as you don't change anything on either vector. As soon as you change something in the data, the data is physically copied behind the scenes and you continue with double memory.
Because this is completely transparent your application needs not wory about this. It is the same mechanism as when you copy a QString for example.
Seneca is right - you try to overwrite an unexisting item. You want to add items, not overwrite them.