qt - QByteArray initialization -


i can initialize qbytearray like:

qbytearray m_data; m_data[0] = 0x0c; m_data[1] = 0x06; m_data[2] = 0x04; m_data[3] = 0x04; m_data[4] = 0x02; m_data[5] = 0x00; 

but more compact, like:

qbytearray m_data{0x0c, 0x06, 0x04, 0x04, 0x02, 0x00}; 

unfortunately, form isn't allowed:

error: not convert '{12, 6, 4, 4, 2, 0}' '<brace-enclosed initializer list>' 'qbytearray'      qbytearray m_data{0x0c, 0x06, 0x04, 0x04, 0x02, 0x00};                                                           ^ 

are there alternatives (closer dream)?

(does c++11/14/17 helps on issue?)

you let template figure out how many elements in list:

using myarr = char[];  template <size_t n> qbytearray make_qbytearray(const char(&a)[n]) {     return {a,n}; } 

then create qbytearray with:

auto  m_data{make_qbytearray(myarr{0x0c, 0x06, 0x04, 0x04, 0x02, 0x00})}; 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -