Results 1 to 2 of 2

Thread: QByteArray initialization

  1. #1
    Join Date
    Jul 2017
    Posts
    13
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QByteArray initialization

    ErrorScreenShot.jpgHi Friends

    I am facing an issue in QByteArray when QByteArray Initialization.

    I can initialize a QByteArray like:


    Qt Code:
    1. QByteArray m_data;
    2. m_data[0] = 0x0c;
    3. m_data[1] = 0x06;
    4. m_data[2] = 0x04;
    5. m_data[3] = 0x04;
    6. m_data[4] = 0x02;
    7. m_data[5] = 0x00;
    To copy to clipboard, switch view to plain text mode 


    But I would like something more compact, like:

    Qt Code:
    1. QByteArray m_data{0x0c, 0x06, 0x04, 0x04, 0x02, 0x00};
    To copy to clipboard, switch view to plain text mode 

    Unfortunately, this form isn't allowed:

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


    I want to pass m_data(array Data ) in emit signal. Any code example and snippet will be helpful.


    Thanks In Advance

    Best Regards
    Vivek Yuvan
    Last edited by vivekyuvan; 20th September 2017 at 11:56.

  2. #2
    Join Date
    Jan 2017
    Posts
    58
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QByteArray initialization

    I'm not sure if this is the best way, but this should works:
    Qt Code:
    1. char temp[3] = {0x0c, 0x06, 0x12};
    2. QByteArray m_data = QByteArray((char*)temp, 3);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 6
    Last Post: 14th May 2014, 13:14
  2. QDesktopWidget initialization
    By drweilert in forum Qt Programming
    Replies: 4
    Last Post: 8th May 2011, 20:42
  3. Replies: 9
    Last Post: 25th July 2009, 14:27
  4. 'new' in initialization list
    By Kumosan in forum General Programming
    Replies: 5
    Last Post: 26th May 2008, 17:09
  5. Initialization code
    By Doug Broadwell in forum Newbie
    Replies: 2
    Last Post: 27th February 2007, 12:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.