Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]Vector problems
Forum Updated to NodeBB v4.3 + New Features

[Solved]Vector problems

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    toho71
    wrote on last edited by
    #1

    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;

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved