Missing template argument before "*" token

  • I have this line of code in two different classes, in similar positions:

    QList * tmp = new QList(lalgExpressionText.split("+"));

    In one case it works perfectly, in another case i get the error mentioned in the subject, is there a reason for this?
    What does such error mean?
    Actually what I need is only to split a string into a list on which I can iterate and do things, if you have other straightforward ways to do it feel free to suggest.

    Please consider that i am a perfect newbye to QT and quite newbye to c++. My programming experience includes basically only php, javascript and LPC (the old object oriented language used in MUDs!). Thus I understand that my questions might seem odd to experts. Thanks in advance.

    [EDIT: code formatting, Volker]

  • QList is a template class, (see http://www.cplusplus.com/doc/tutorial/templates/)

    So you have to define which type of variables it works with ie. two variables of type QList<QString> or QList<int> are a list of qstrings and a list of integers you can't have a pointer to list without knowing what kind of pointer, afaik.

    I guess you observe the different behavior because QList* is a critical error and it never goes to the next point, although if only a line seperates them in a file my compiler would give both as an error.

    for your problem I would use something like
    foreach(QString x, QString("My, String").split(',)) {
    qDebug() << "A part is: " << x;

    Note that foreach is a qt specific language construct but is kinda like for(int i=0; i<10;++i) etc..

  • I believe you meant QStringList, not QList.

  • Additionally: Why do you work with a QList allocated on the heap? That's hardly ever necessary!

  • [quote author="Volker" date="1322761234"]Additionally: Why do you work with a QList allocated on the heap? That's hardly ever necessary![/quote]

    What does "allocated on the heap" means?

  • I see....well, actually I just need to create a list of lists, or vector of vectors, or array of arrays, or whatever. But it seems to be impossible in QT: if i use QLists, then they cannot contain QLists, but they can contain only other types, like qstrings or or int or other, and as I understand it, Qlists can only contain a type of objects at once.
    I wonder if in QT it exists the possibility to create lists of multiple types of objects, included lists.
    Or maybe it is possible to create multidimentional lists?

  • Or in other words, can containers contain containers?

  • Or in other words, can containers contain containers?

    Sure they can! QVector< int > is a type for instance:

    QVector< QVector< int > >


    QList< QHash< unsigned, QWidget* > >

    are perfectly legal.

    PS: After a second reading of your question, a container in general cannot contain multiple types (i.e. you cannot mix doubles and int), however using polymorphism you can do it, by storing pointers. But I'm not sure this was your question.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.