QObject connect error with std::vector<int>

257 Views Asked by At

I am having a struct containing the vector of int and this struct is later used in the class and this is generating a runtime error with the error message,

QObject::connect: cannot queue arguments of type 'QVector' (Make sure 'QVector' is registered using qRegisterMetaType())

struct:

struct Grid {

  std::vector<int> indices;
  int pt_count{};

  Grid()=default;
  ~Grid()=default;

  void add_indice(int _indice) {
    indices.push_back(_indice);
    pt_count++;
  }
};

main.cpp

#include <vector>
#include <struct.h>

int main() {
  std::vector<Grid> grids;
  grids.resize(5);

  for (int i{0}; i < 5; i++){
    for (int j {0}; j < 10; j++){
      grids.at(i).add_indice(j);
    }
  }

  return 0;    
}

why am i getting the error mentioned above? can anybody help with this?

Thank you!

1

There are 1 best solutions below

0
Top-Master On

That message is about QVector and has nothing to do with std::vector (at least not at time of writing).

Add somewhere (before that error happens, maybe in main), something like:

#include <QVector>
#include <QMetaType>

// ...

void myFunc() {
    int metatype_id = qRegisterMetaType< QVector >("QVector");
}