Results 1 to 3 of 3

Thread: [closed] How to fill QList with struct data more elegant

  1. #1
    Join Date
    Apr 2014
    Posts
    116
    Thanks
    8
    Qt products
    Qt5
    Platforms
    MacOS X

    Default [closed] How to fill QList with struct data more elegant

    Hi,

    I have a QList with a custom data type. All I found on filling the list looked like this:
    Qt Code:
    1. customStruct newStruct;
    2. newStruct.prperty1 = xy;
    3. newStruct.prperty2 = xy;
    4. newStruct.prperty3 = xy;
    5. [...]
    6. newStruct.prpertyN = xy;
    7. list.append(newStruct);
    To copy to clipboard, switch view to plain text mode 
    Is there a more elegant way to do that? So that everything is on one line or maybe two? Or does one line only work if I create a new class?
    Last edited by KeineAhnung; 8th May 2014 at 10:28.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: [open] How to fill QList with struct data more elegant

    You can add a constructor to customStruct to that you can write

    Qt Code:
    1. list.append(customStruct(......));
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. #3
    Join Date
    Apr 2014
    Posts
    116
    Thanks
    8
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: [open] How to fill QList with struct data more elegant

    Okay, I thought I had tried that...
    Never the less I already switched to a class. Maybe I will add a signal as well.

Similar Threads

  1. QList<struct>
    By Axsis in forum Newbie
    Replies: 11
    Last Post: 12th October 2015, 08:48
  2. how to fill Qlist in minimum time
    By shivendra46d in forum Newbie
    Replies: 2
    Last Post: 26th August 2013, 13:08
  3. remove struct from qlist
    By mero in forum Qt Programming
    Replies: 2
    Last Post: 26th October 2012, 15:58
  4. How to fill a QList<struct> ?
    By falconium in forum Newbie
    Replies: 1
    Last Post: 1st March 2011, 22:59
  5. sharing struct data throughout program
    By vonCZ in forum Newbie
    Replies: 3
    Last Post: 9th July 2007, 18:21

Tags for this Thread

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.