Results 1 to 2 of 2

Thread: How to declare QRadioButton number dynamically

  1. #1
    Join Date
    Aug 2016
    Posts
    2
    Qt products
    Qt5
    Platforms
    MacOS X Windows Android

    Default How to declare QRadioButton number dynamically

    Hi

    As title says, this is my code

    ...
    QStringList test;
    ...
    QRadioButton *Btn[test.size()];

    but it show error "it needs constants"

    i don't want to rewrite like this QRadioButton *Btn[100];

    please give me some advice

    thanks!

  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: How to declare QRadioButton number dynamically

    When you declare an array on the stack, then the compiler needs to know the size at compile time.

    You can either allocate an array on the heap (as that happens during runtime) or do the smart thing and use a container, e.g. QVector.

    Cheers,
    _

Similar Threads

  1. QRadioButton and QDataWidgetMapper
    By SimonSchmeisser in forum Qt Programming
    Replies: 3
    Last Post: 24th June 2015, 15:28
  2. QRadioButton and QButtonGroup
    By joseche in forum Qt Programming
    Replies: 2
    Last Post: 28th July 2012, 12:45
  3. Replies: 1
    Last Post: 5th March 2012, 06:34
  4. QRadioButton
    By sonuani in forum Newbie
    Replies: 1
    Last Post: 20th February 2008, 09:30
  5. QRadioButton
    By sabeesh in forum Qt Programming
    Replies: 3
    Last Post: 8th October 2007, 07:25

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.