I'm having problem with understanding some of QList behavior.
#include <QList>
#include <iostream>
using namespace std;
int main()
{
QList<double> *myList;
myList = new QList<double>;
double myNumber;
double ABC;
for (int i=0; i<1000000; i++)
{
myNumber = i;
myList->append(myNumber);
ABC = myList[i]; //<----------!!!!!!!!!!!!!!!!!!!
cout << ABC << endl;
}
cout << "Done!" << endl;
return 0;
}
I get compilation error cannot convert ‘QList’ to ‘double’ in assignment at marked line. It works when I use ABC = myList.at(i)
, but QT reference seems to say that at()
and [] operator
is same thing.
Does anybody know what makes the difference?
Thanks
That's because operator[]
should be applied to a QList
object, but myList
is a pointer to QList
.
Try
ABC = (*myList)[i];
instead. (Also, the correct syntax should be myList->at(i)
instead of myList.at(i)
.)