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] Problem with QVector<enum> return
QtWS25 Last Chance

[Solved] Problem with QVector<enum> return

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.9k Views
  • 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 Offline
    I Offline
    igorland
    wrote on last edited by
    #1

    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
    0
    • T Offline
      T Offline
      t3685
      wrote on last edited by
      #2

      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
      0
      • I Offline
        I Offline
        igorland
        wrote on last edited by
        #3

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

        Best.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #4

          Why are you using a bare C array at all?

          1 Reply Last reply
          0
          • I Offline
            I Offline
            igorland
            wrote on last edited by
            #5

            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
            0

            • Login

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