Results 1 to 11 of 11

Thread: How to create lineEdits as an array?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2016
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: How to create lineEdits as an array?

    Thank you for your help, Lesiok.
    I am going to try the codes from superdialog.zip

    When I tried to implement the code you gave before into a widget.cpp indeed qle_list was constructed as a QList of type QLineEdit, but the elements were undefined and I could not find how to get the lineEdits on a window.
    It is strange that I could nowhere find a straightforward solution. Until now I just use a large series of code lines like:
    QLineEdit * text[50];
    text[1] = ui->lineEdit_1
    text[2] = ui->lineEdit_2
    ......
    text[50] =ui->lineEdit_50

    I can imagine that it can not be done easier with a nice system as Qt.
    But maybe that is why I am still a newbe

  2. #2
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to create lineEdits as an array?

    I guess you are trying to do this.

    Qt Code:
    1. #include <QApplication>
    2. #include <QDialog>
    3. #include <QLineEdit>
    4. #include <QVBoxLayout>
    5. #include <QList>
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. QApplication a(argc, argv);
    10.  
    11. QVBoxLayout * vLayout = new QVBoxLayout(&w);
    12. QList<QLineEdit *> qle_list;
    13.  
    14. for(int i = 0; i < 10; ++i)
    15. {
    16. qle_list.append(new QLineEdit());
    17. qle_list.at(i)->setObjectName(QString("lineEdit%1").arg(i)); // It's easier to recognize an object by name
    18. vLayout->addWidget(qle_list.at(i));
    19. }
    20. w.setLayout(vLayout);
    21. w.show();
    22.  
    23. return a.exec();
    24. }
    To copy to clipboard, switch view to plain text mode 

    For example, you can get the object name by
    Qt Code:
    1. for-loop: qle_list.at(i)->objectName();
    To copy to clipboard, switch view to plain text mode 
    Last edited by rawfool; 17th November 2016 at 09:00.

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

    Default Re: How to create lineEdits as an array?

    Quote Originally Posted by Wolletje View Post
    Thank you for your help, Lesiok.
    I am going to try the codes from superdialog.zip

    When I tried to implement the code you gave before into a widget.cpp indeed qle_list was constructed as a QList of type QLineEdit, but the elements were undefined and I could not find how to get the lineEdits on a window.
    It is strange that I could nowhere find a straightforward solution. Until now I just use a large series of code lines like:
    QLineEdit * text[50];
    text[1] = ui->lineEdit_1
    text[2] = ui->lineEdit_2
    ......
    text[50] =ui->lineEdit_50

    I can imagine that it can not be done easier with a nice system as Qt.
    But maybe that is why I am still a newbe
    I do not think you understand my example. QLineEdit objects are created in the code and not in the UI file.

  4. #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: How to create lineEdits as an array?

    If you want to create the buttons in Qt Designer, you can still retrieve them into a list using QObject::findChildren().

    Cheers,
    _

Similar Threads

  1. How to create a 2dimensional array in Qt
    By athulms in forum Qt Programming
    Replies: 1
    Last Post: 29th July 2011, 07:45
  2. Qt Designer How to create an array of objects??
    By dominate in forum Qt Tools
    Replies: 2
    Last Post: 22nd January 2011, 16:34
  3. How to Create control Array in QT4
    By umulingu in forum Qt Programming
    Replies: 4
    Last Post: 8th October 2009, 15:31
  4. how can i create array of lineedits?
    By BalaQT in forum Qt Programming
    Replies: 1
    Last Post: 20th August 2009, 08:17
  5. Create an array of Widgets
    By gt.beta2 in forum Qt Tools
    Replies: 4
    Last Post: 25th February 2009, 19:44

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.