The function accepts a vector by non-const reference implying that it wants to modify it. You are passing a temporary object returned from toStdVector() and this is likely the problem. Create an explicit vector to pass in. With my compiler:
struct A {};
void SetVector(std::vector<A> &v) {
}
QVector<A> a;
SetVector(a.toStdVector());
// generates
// main.cpp:14:30: error: invalid initialization of non-const reference of type ‘std::vector<A>&’ from an rvalue of type ‘std::vector<A>’
// main.cpp:6:6: error: in passing argument 1 of ‘void SetVector(std::vector<A>&)’
std::vector<A> b = a.toStdVector();
SetVector(b);
// compiles fine.
struct A {};
void SetVector(std::vector<A> &v) {
}
QVector<A> a;
SetVector(a.toStdVector());
// generates
// main.cpp:14:30: error: invalid initialization of non-const reference of type ‘std::vector<A>&’ from an rvalue of type ‘std::vector<A>’
// main.cpp:6:6: error: in passing argument 1 of ‘void SetVector(std::vector<A>&)’
std::vector<A> b = a.toStdVector();
SetVector(b);
// compiles fine.
To copy to clipboard, switch view to plain text mode
Bookmarks