Results 1 to 7 of 7

Thread: dynamically unknown size of label array

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dynamically unknown size of label array

    Don't use an array. Use QVector or QList as Radek said. Both of them don't need initial size.

  2. #2
    Join Date
    Jan 2015
    Posts
    35
    Thanks
    20
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: dynamically unknown size of label array

    Thanks Radek and Lesiok.

    I changed from array to QList. I got it.

  3. #3
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: dynamically unknown size of label array

    (1) The error: You cannot declare a "plain" array with a variable size
    Qt Code:
    1. private:
    2. int n;
    3. QLabel *mylabel[n]; // compile error
    To copy to clipboard, switch view to plain text mode 
    Tne n needed be an initialized const int.

    (2) IMO, QVector is better here. QVector is a dynamic array while QList is a linked list. Nevertheless both of them will serve you good.

  4. The following user says thank you to Radek for this useful post:

    binary001 (8th March 2015)

  5. #4
    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: dynamically unknown size of label array

    QList is not a linked list, but I agree that QVector is more appropriate here since the length is already known at creation time.

    Cheers,
    _

Similar Threads

  1. Replies: 7
    Last Post: 29th September 2014, 14:31
  2. Replies: 1
    Last Post: 11th July 2014, 14:01
  3. Replies: 2
    Last Post: 5th September 2013, 15:29
  4. two dimensional array, size determined dynamically
    By feraudyh in forum General Programming
    Replies: 9
    Last Post: 10th June 2010, 03:00
  5. Replies: 1
    Last Post: 24th October 2006, 16:40

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
  •  
Qt is a trademark of The Qt Company.