[Solved] Problem with QVector<enum> return
-
Hello. I am facing a strange problem.
Pax.h
[code]
#ifndef PAX_H
#define PAX_H#include <cstdlib>
#include <ctime>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <QDebug>
#include <QVector>class Pax
{
public:
Pax();
~Pax();
enum pax { E, M, F, C };
QVector<pax> getSeatsArray();private: pax seats[50];
};
#endif // PAX_H
[/code]Pax.cpp
[code]
#include "Pax.h"Pax::Pax()
: seats {E, E, E, E, E, E, E, E, E, E, E, E, E, E, E, E, E, E, E, E, E, E, E, E, E, E, E, E,
E, E, E, E, E, E, E, E, E, E, E, E, E, E, E, E, E, E, E, E, E, E}
{}
// Return an array to the main function
QVector<pax> Pax::getSeatsArray()
{std::vector<pax> seatsVectorStd(seats, seats + sizeof seats / sizeof seats[0]); QVector seatsVector<pax>; seatsVector.fromStdVector(seatsVectorStd); return seatsVector; qDebug() << seatsVector;
}
[/code]
So, basically, I have initialized an array. Then I do manipulations with the array changing its values. After that, I want to pass the array to the main class by first converting it into a QVector (to avoid using pointers). The problem is that Qt gives me an error in this line:
[code]
QVector<pax> Pax::getSeatsArray()
[/code]saying: "'pax' was not declared in this scope.
Weird because everywhere else, the cpp file sees the pax as a declared enum. Hm, have no idea what is going on.
Thanks a lot!
-
I first created the project in Code::Blocks for a console. Now I am developing GUI and I simply copy and paste my former code. Sometimes I change the code to include Qt classes, sometime, like in this case, I just leave it as it is. But you have a valid point. Thanks!