View Full Version : [open] HowTo work with QPairs in a QList
KeineAhnung
5th May 2014, 14:31
Hi,
I try to use QPair to store connected data in a QList:
QList<QPair<QString, int> > status;
...
status.append(QPair("test", 0));
But I get an error:
cannot refer to class template 'QPair' without a template argument list
What does this mean?
If I click on "template is declared here" in the error log it goes to QGRAPHICSITEMANIMATION_H and points to this line:
template <class T1, class T2> struct QPair;
I copied this from an example in the documentation so I am really confused that it is not working.
sulliwk06
5th May 2014, 15:25
From: http://qt-project.org/doc/qt-4.8/qpair.html#QPair-2
Related Non-Members
QPair<T1, T2> qMakePair ( const T1 & value1, const T2 & value2 )
Returns a QPair<T1, T2> that contains value1 and value2. Example:
QList<QPair<int, double> > list;
list.append(qMakePair(66, 3.14159));
This is equivalent to QPair<T1, T2>(value1, value2), but usually requires less typing.
So try it with
status.append(qMakePair("test",0))
or
status.append(QPair<QString, int>("test",0))
KeineAhnung
5th May 2014, 15:36
I tried status.append(qMakePair("test", 0)); and that looks better know but I still get an error:
.../Qt/5.2.1/clang_64/lib/QtCore.framework/Headers/qpair.h:57: Error: array initializer must be an initializer list or string literal
QPair(const T1 &t1, const T2 &t2) : first(t1), second(t2) {}
.../Qt/5.2.1/clang_64/lib/QtCore.framework/Headers/qpair.h:117: in instantiation of member function 'QPair<char [10], int>::QPair' requested here
return QPair<T1, T2>(x, y);
What is that supposed to mean?
sulliwk06
5th May 2014, 16:03
looks like it didn't interpret "test" as a QString.
in instantiation of member function 'QPair<char [10], int>::QPair' requested here
Try:
status.append(qMakePair(QString("test"),0))
KeineAhnung
5th May 2014, 16:14
Thanks for the help! I need to get better in reading error =)
anda_skoa
5th May 2014, 16:29
Just saying: in a lot of cases it is way easier to just use a custom struct with two named fields instead of a pair :)
Cheers,
_
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.