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] Initialise QVector of enums

[SOLVED] Initialise QVector of enums

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.5k Views 3 Watching
  • 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.
  • H Offline
    H Offline
    holzkohlengrill
    wrote on last edited by holzkohlengrill
    #1

    I have the following class:

    // data.h
    class Data {
    public:
    	Data();
    	// returns a QVector of type T of all elements stored
    	template<typename T>
    	QVector<T> ShowAllEntriesOfInput(const T &input) const;
    private:
    	struct Entry {
    		QString type;
    		QDate date;
    		int amount;
    	};
    	QVector<Entry> entries;
    	QStringList types;
    };
    
    // data.cpp
    // ...
    Data::Data() {
    //////////////
    // error is in the following line:
    // error: no match for 'operator=' (operand types are 'QVector<Data::Entry>'
    // and '<brace-enclosed initializer list>')  entries = {
    //                                                   ^
    //////////////
    	entries = {
    		{"car", 110,  QDate{2014, 03, 02}},
    		{"house", 80, QDate{2016, 05, 05}}
    					};
    }
    //....
    

    Do you know what is wrong (error is commented in data.cpp) with my initialiser list?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      it seems right syntax
      http://stackoverflow.com/questions/15641318/anyone-give-me-an-example-to-use-qvectorqvectorstdinitializer-listt-args

      but I did wonder
      struct Entry is
      QString type;
      QDate date;
      int amount;

      but you say
      {"car", 110, QDate{2014, 03, 02}},

      string, int, date ?

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Hi!

        Data::Data()
            : entries({ 
        {"car", QDate{2014, 03, 02}, 110},
        {"house", QDate{2016, 05, 05}, 80}
                      })
        {
        }
        

        or

        Data::Data()
        {
            entries = {
            {"car", QDate{2014, 03, 02}, 110},
            {"house", QDate{2016, 05, 05}, 80}
                          };
        }
        
        1 Reply Last reply
        1
        • H Offline
          H Offline
          holzkohlengrill
          wrote on last edited by
          #4

          Hey, thanks. i just realised it a second ago that I just wrote it in the wrong order xD

          Thank you anyway!!

          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