Results 1 to 5 of 5

Thread: How to Create control Array in QT4

  1. #1
    Join Date
    Jul 2009
    Posts
    49
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to Create control Array in QT4

    Hai

    How to create control array like other programming languages.
    and how to convert integer to string?..

    Qt Code:
    1. int i=8;
    2.  
    3. lineEdit->setText(tr("%1").arg(i)); // its working is there any other way..
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Apr 2008
    Posts
    196
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    1

    Default Re: How to Create control Array in QT4

    Qt Code:
    1. QString::number(i)
    To copy to clipboard, switch view to plain text mode 
    What do you mean with "control array like other programming languages"?

    Best Regards
    NoRulez

  3. #3
    Join Date
    Jul 2009
    Posts
    49
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to Create control Array in QT4

    Thanks

    Control Array means group of controls with same name.

    Eg.

    I want 10 lineEdit in same name [lineEdit] with index

    Qt Code:
    1. lineEdit[0]->setText("suresh");
    2. lineEdit[1]->setText("suresh");
    3. lineEdit[2]->setText("suresh");
    4. .
    5. .
    6. .
    7. lineEdit[9]->setText("suresh");
    To copy to clipboard, switch view to plain text mode 
    How to do this in QT4?

  4. #4
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to Create control Array in QT4

    Something like this :
    Qt Code:
    1. QDialog dlg;
    2. QVBoxLayout *vl=new QVBoxLayout(&dlg);
    3. dlg.setLayout(vl);
    4. QList <QPushButton*> btnList;
    5. for(int i=0;i<10;i++)
    6. {
    7. QPushButton *btn = new QPushButton("Hello", &dlg);
    8. vl->addWidget(btn);
    9. btnList << btn;
    10. }
    11. dlg.exec();
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Apr 2008
    Posts
    196
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    1

    Default Re: How to Create control Array in QT4

    It's better to use an iterator like the following
    Qt Code:
    1. QList<QLineEdit*> lineEdits;
    2. for(QList<QLineEdit*>::iterator iter = lineEdits.begin(); iter != lineEdits.end(); ++iter) {
    3. (*iter)->setText("Some Text");
    4. // In Qt i think you can also use the following
    5. // iter->setText("Some Text");
    6. }
    To copy to clipboard, switch view to plain text mode 
    or an foreach loop:
    Qt Code:
    1. foreach(QLineEdit* le, lineEdits) {
    2. le->setText("Some Text");
    3. }
    To copy to clipboard, switch view to plain text mode 

    Best Regards
    NoRulez

Similar Threads

  1. How To Create Array of Widgets in Qt4?
    By redhat in forum Newbie
    Replies: 4
    Last Post: 27th April 2009, 10:37
  2. Create an array of Widgets
    By gt.beta2 in forum Qt Tools
    Replies: 4
    Last Post: 25th February 2009, 19:44
  3. Using a 2d data array to create an image
    By dbrmik in forum Newbie
    Replies: 20
    Last Post: 28th October 2008, 17:22
  4. How to create QPixmap from unsigned character array?
    By rashidbutt in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 18:25
  5. Replies: 6
    Last Post: 3rd February 2006, 09: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.