November 30, 2011

mkcerusky mkcerusky
Lab Rat
17 posts

missing template argument before “*” token

 

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

  1. 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]

8 replies

December 1, 2011

LarsG LarsG
Lab Rat
8 posts

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

  1. foreach(QString x, QString("My, String").split(',)) {
  2.        qDebug() << "A part is: " << x;
  3. }

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

December 1, 2011

veeeee_d veeeee_d
Lab Rat
56 posts

I believe you meant QStringList, not QList.

December 1, 2011

Volker Volker
Ant Farmer
5428 posts

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

October 7, 2012

mkcerusky mkcerusky
Lab Rat
17 posts
Volker wrote:
Additionally: Why do you work with a QList allocated on the heap? That’s hardly ever necessary!

What does “allocated on the heap” means?

October 8, 2012

Lukas Geyer Lukas Geyer
Lab Rat
2074 posts

http://www.learncpp.com/cpp-tutorial/79-the-stack-and-the-heap/

May 5, 2013

mkcerusky mkcerusky
Lab Rat
17 posts

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?

May 5, 2013

mkcerusky mkcerusky
Lab Rat
17 posts

Or in other words, can containers contain containers?

May 6, 2013

Johan Solo Johan Solo
Ant Farmer
120 posts
mkcerusky wrote:
Or in other words, can containers contain containers?

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

  1. QVector< QVector< int > >

or

  1. 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.

 Signature 

Linux : you can find worse, but it’s more expensive.

 
  ‹‹ When mixing QML, C++ and MySql how to implement refresh() method for the model?      Need help on building ’Help’ from scratch. ››

You must log in to post a reply. Not a member yet? Register here!