Page 2 of 2 FirstFirst 12
Results 21 to 22 of 22

Thread: Using gui objectNames when coding

  1. #21
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using gui objectNames when coding

    Use an array. Something like:

    Qt Code:
    1. QButton *myButtons[16];
    2. myButtons[0] = ui->p1;
    3. myButtons[1] = ui->p2;
    4. ...
    To copy to clipboard, switch view to plain text mode 

    (there are other more efficient ways to initialise the array depending on the scope of the array, but this will work regardless)

    then you can do:

    Qt Code:
    1. for (int i = 0; i < 16; i ++)
    2. {
    3. myButtons[i]->setText("something");
    4. }
    To copy to clipboard, switch view to plain text mode 

  2. #22
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using gui objectNames when coding

    From the documentation : this example returns a child QPushButton of parentWidget named "button1":

    Qt Code:
    1. QPushButton *button = parentWidget->findChild<QPushButton *>("button1");
    To copy to clipboard, switch view to plain text mode 

    You can use QString("p%1").arg(i) to create the strings "p1", "p2", "p3", ...

    Regards,
    Marc

Similar Threads

  1. Coding a game with Qt
    By seltra in forum Qt Programming
    Replies: 5
    Last Post: 5th October 2010, 20:49
  2. VC++ 9.0 coding Symbian ?
    By nhs_0702 in forum Qt Programming
    Replies: 0
    Last Post: 3rd May 2010, 03:48
  3. Replies: 6
    Last Post: 29th January 2010, 23:56
  4. Replies: 0
    Last Post: 18th July 2009, 13:07
  5. What is your coding style ??
    By guestgulkan in forum General Discussion
    Replies: 9
    Last Post: 29th May 2006, 09:22

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.