qCopy assumes that the target elements allready exist and then overwrites them.
So this example must be:
void test()
{
QVector< QPair<
int ,
QString > > first;
for(int iIdx = 0; iIdx <5 ; ++iIdx )
first.
push_back(QPair<
int ,
QString >
(iIdx ,
"aaa") );
QVector< QPair<
int ,
QString > > second
(first.
count());
qCopy(first.begin(), first.end(), second.begin());
}
void test()
{
QVector< QPair< int , QString > > first;
for(int iIdx = 0; iIdx <5 ; ++iIdx )
first.push_back(QPair< int , QString >(iIdx , "aaa") );
QVector< QPair< int , QString > > second(first.count());
qCopy(first.begin(), first.end(), second.begin());
}
To copy to clipboard, switch view to plain text mode
Maybe this would be better:
void test()
{
QVector< QPair<
int ,
QString > > first;
for(int iIdx = 0; iIdx <5 ; ++iIdx )
first.
push_back(QPair<
int ,
QString >
(iIdx ,
"aaa") );
QVector< QPair<
int ,
QString > > second
(first
);
}
void test()
{
QVector< QPair< int , QString > > first;
for(int iIdx = 0; iIdx <5 ; ++iIdx )
first.push_back(QPair< int , QString >(iIdx , "aaa") );
QVector< QPair< int , QString > > second(first);
}
To copy to clipboard, switch view to plain text mode
Because it can share data until a write operation is made on either vector.
Bookmarks