[Solved]Vector problems



  • I'm using a qvector in my program to store some widgets

    But I have som problem s with the instaciation of the vector

    in my headerfile i simply sets the name and the type of object to the vector.

    @Qvector<myclass*> myvector;@

    but in the code where I'm going to use it I do like this

    @myvector = new Qvector ();@
    should be
    @myvector = new Qvector <myClass>();@

    the compiler doesn't like it at all;

    any ideas;



  • Basic C++ really. You are creating your vector on the stack. A QVector<myclass*> is created as soon as the class it is declared on is instantiated as an object. Then, when you want to use it, you suddenly tell the application that you want to put a pointer to a QVector<> on that address instead. That is wrong on two levels: first of all, a pointer to an object of class X is a different type than class X itself, so a pointer to a QVector is a different type than QVector itself.

    The other mistake is that you are trying to instantiate a QVector without using a contents type. QVector is a template class. That means that it only becomes a complete type when you specify the required arguments properly. As with all Qt containter classes, you need to specify the type to store. You did that correctly in your declaration, but you also need to do it in your implementation. Just QVector is not a valid type, but QVector<MyClass*> is. You can obviously not create an instance of an invalid type...


Log in to reply
 

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