Qt World Summit: Register Today!

[SOLVED] Pass QList with undefined size

  • Hey there

    I'm afraid that this isn't working anyway, but maybe somebody has a good idea.

    I'm looking for the possibility to pass a QList Array to a function as a parameter. So far everything is fine. But now, the point is, I don't know how big the array is and so I can't do further actions with the data. Below a little example:

    void MyFunction(QList<int> passedList[])
    myList[0] = passedList[0];
    myList[1] = passedList[1];

    This is how it works, but therefore I need to know how big the passed list is going to be. How could this be achieved without that information?

  • When you pass an c-style array to a function add another parameter and pass the size too.
    Also you can use another QList and pass a QList<QList<int> > param and then you don't need to pass the size anymore.

  • QList in a QList, already tried, didn't worked and why. Because of the space between > and >. True story! : )

  • Yeap, compilers require you to write @QList<QList<int> >@ because ">>" is an operator and the compilers are too stupid to distinguish between those two meanings. That is a well known pitfall.

    This was changed in the new C++11 standard by the way.

Log in to reply