Global QVector struct how to?
-
Hey guys!
Need some help on how to get a global QVector and a struct working without LNK2001/LNK2005 errors.
Here is my global.h file:
#ifndef GLOBAL_H #define GLOBAL_H #include <QString> #include <QVector> struct gUser { int id; QString name; }; extern QVector<gUser> Users; #endif // GLOBAL_H
In my cpp files i include the global.h from above and get LNK errors. I did try serval other ways but non of them works so far. Is there something wrong with my declaration or? I don't know and hope some onre here can help me out.
Thanks!
-
@qDebug said in Global QVector struct how to?:
extern QVector<gUser> Users;
One (and only one)
.cpp
file must define storage for the variable:QVector<gUser> Users;
The fact that it is a vector of
struct
s is not relevant. -
Thank you, that solved my problem :)
Now that you wrote it, i remember how it worked in c++. Only one cpp file QVector<gUser> Users; and others extern QVector<gUser> Users; for access.
Thanks!
3/3