[odb-users] std::map<Entity, int>

Adnan RIHAN axel50397 at gmail.com
Sat Nov 22 18:46:19 EST 2014


Hi there,

I’m trying to store a Map of another entity as key, and a quantity as value, in an Entity.
I’m on a Cashier app.

I have an invoice, which contains an QMap<QSharedPointer<Product>, quantity> (quantity as uint).
Invoice.hpp:
> private:
>     QMap<QSharedPointer<Product>, uint>    cart;
> [...]
> #pragma db member(Invoice::cart) table("invoice_carts") \
>                                  id_column("invoice_id") \
>                                  key_column("product_id") \
>                                  key_type("UNSIGNED INT") \
>                                  value_column("quantity”)

When compiling, I have these errors:
> In file included from /Users/Max13/Dev/System/LGC/Desktop/apps/LGC/src/Models/Invoice/Invoice-odb.cxx:7:
> In file included from /Users/Max13/Dev/System/LGC/Desktop/apps/LGC/src/Models/Invoice/Invoice-odb.hxx:22:
> In file included from /usr/local/include/odb/qt/basic/sqlite/qstring-traits.hxx:16:
> /usr/local/include/odb/sqlite/traits.hxx:216:13: error: cannot convert 'Product' to 'image_type' (aka 'long long') without a conversion operator
>         i = image_type (v);
>             ^~~~~~~~~~~~~
> /usr/local/include/odb/sqlite/traits.hxx:172:20: note: in instantiation of member function 'odb::sqlite::default_value_traits<Product, 0>::set_image' requested here
>           vtraits::set_image (i, is_null, wtraits::get_ref (v));
>                    ^
> /Users/Max13/Dev/System/LGC/Desktop/apps/LGC/src/Models/Invoice/Invoice-odb.cxx:144:33: note: in instantiation of member function 'odb::sqlite::wrapped_value_traits<QSharedPointer<Product>, 0, true>::set_image' requested here
>           sqlite::id_integer >::set_image (
>                                 ^
> In file included from /Users/Max13/Dev/System/LGC/Desktop/apps/LGC/src/Models/Invoice/Invoice-odb.cxx:7:
> In file included from /Users/Max13/Dev/System/LGC/Desktop/apps/LGC/src/Models/Invoice/Invoice-odb.hxx:22:
> In file included from /usr/local/include/odb/qt/basic/sqlite/qstring-traits.hxx:16:
> /usr/local/include/odb/sqlite/traits.hxx:207:15: error: no matching conversion for functional-style cast from 'const image_type' (aka 'const long long') to 'Product'
>           v = T (i);
>               ^~~~
> /usr/local/include/odb/sqlite/traits.hxx:163:20: note: in instantiation of member function 'odb::sqlite::default_value_traits<Product, 0>::set_value' requested here
>           vtraits::set_value (wtraits::set_ref (v), i, is_null);
>                    ^
> /Users/Max13/Dev/System/LGC/Desktop/apps/LGC/src/Models/Invoice/Invoice-odb.cxx:181:33: note: in instantiation of member function 'odb::sqlite::wrapped_value_traits<QSharedPointer<Product>, 0, true>::set_value' requested here
>           sqlite::id_integer >::set_value (
>                                 ^
> /Users/Max13/Dev/System/LGC/Desktop/apps/LGC/src/Models/Invoice/../Product/Product.hpp:22:7: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'const image_type' (aka 'const long long') to 'const Product' for 1st argument
> class Product : public BaseModel
>       ^
> /Users/Max13/Dev/System/LGC/Desktop/apps/LGC/src/Models/Invoice/../Product/Product.hpp:44:9: note: candidate constructor not viable: no known conversion from 'const image_type' (aka 'const long long') to 'QObject *' for 1st argument
>         Product(QObject *parent = 0);
>         ^
> /Users/Max13/Dev/System/LGC/Desktop/apps/LGC/src/Models/Invoice/../Product/Product.hpp:45:9: note: candidate constructor not viable: requires at least 2 arguments, but 1 was provided
>         Product(
>         ^
> 2 errors generated.

What I understand, is that the key is a long long (object_id) and I’m trying to obtain the actual object having for id the object_id.

So, my question is: Is it supported? Or am I missing something?
My idea, if it’s not supported, is to create a class having 3 properties: id, object, quantity, and store it in Invoices as a set. I prefer including that as a map.

Thanks for your help.
--  
Cordialement, Adnan RIHAN.
Directeur-Gérant de Eolis-Software, société de services informatiques.  

GPG: 5675-62BA (https://keybase.io/max13/key.asc)
-> Si vous n'utilisez pas GPG mais souhaitez quand même m’envoyer un e-mail chiffré: (https://encrypt.to/0x567562BA).



More information about the odb-users mailing list