Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    [Solved] Problem with QVector<enum> return

    General and Desktop
    3
    5
    1673
    Loading More Posts
    • 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.
    • I
      igorland last edited by

      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!

      1 Reply Last reply Reply Quote 0
      • T
        t3685 last edited by

        You need to change the return type in Pax.cpp to @ QVectorPax::pax Pax::getSeatsArray()
        @

        By the way, why are you first creating a std::vector to fill a QVector?

        1 Reply Last reply Reply Quote 0
        • I
          igorland last edited by

          Thanks! Yeah, std::vector is not needed, you are right!

          Best.

          1 Reply Last reply Reply Quote 0
          • C
            ChrisW67 last edited by

            Why are you using a bare C array at all?

            1 Reply Last reply Reply Quote 0
            • I
              igorland last edited by

              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!

              1 Reply Last reply Reply Quote 0
              • First post
                Last post