Results 1 to 7 of 7

Thread: Accessing children

  1. #1
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Accessing children

    Hello friends,

    when I create a tabwidget say like this :

    Qt Code:
    1. m_qtbw_myTab = new QTabWidget(this);
    2.  
    3. for (int i = 0; i < m_DetailInfos.size(); ++i)
    4. {
    5. QWidget* customWidget1 = new QWidget(m_qtbw_OrderTab) ;
    6. QGridLayout* myLayout = new QGridLayout();
    7. QLabel * qlbl_Nr = new QLabel(tr("Auftrag"),customWidget1);
    8. qlbl_Nr->setObjectName("qlbl_Nr_"+m_DetailInfos.at(i).value(0).toString());
    9. QLineEdit * qle_Nr = new QLineEdit(customWidget1);
    10. qle_Nr->setObjectName("qle_Nr_"+m_DetailInfos.at(i).value(0).toString());
    11. qle_Nr->setText(m_DetailInfos.at(i).value(0).toString());
    12. qle_Nr->setEnabled(false);
    13. myLayout->addWidget(qlbl_Nr,0,0,1,1,Qt::AlignLeft);
    14. myLayout->addWidget(qle_Nr,0,1,1,1,Qt::AlignLeft);
    15. customWidget1->setLayout(myLayout);
    16.  
    17. m_qtbw_myTab->addTab(customWidget1,m_DetailInfos.at(i).value(0).toString());
    18. }
    To copy to clipboard, switch view to plain text mode 

    And I want access the widget in a special tab I do that with:
    Qt Code:
    1. QWidget * myWidget = qobject_cast<QWidget *>(m_qtbw_myTab->widget(0));
    To copy to clipboard, switch view to plain text mode 

    But what about accessing the Lineedit in a Widget??

    I see the children during debugging and try this:

    Qt Code:
    1. QLineEdit * myedit = qobject_cast<QLineEdit *>(myWidget->childAt(1,0));//lineedit
    To copy to clipboard, switch view to plain text mode 

    but I get a crash.

    Can I access the components on the widget without subclassing the Widget??

    Thanx in advance.

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

    Default Re: Accessing children

    Wouldn't it make more sense to store the value of the QLineEdit pointer and use that rather than using magic indexes which may change?

  3. #3
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Accessing children

    I don´t know if it make sense, cause it is the first situation for me to implement this thing.
    What do you mean exactly with storing pointers?

    QLineEdit& m_ptr_qle;
    m_ptr_qle = &QLineEdit;

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

    Default Re: Accessing children

    Well, you already have the pointer:

    Qt Code:
    1. QLineEdit * qle_Nr = new QLineEdit(customWidget1);
    To copy to clipboard, switch view to plain text mode 

    So why not assign this somewhere rather than throwing it away?

    Qt Code:
    1. m_DetailInfoUI[i].LineEdit = new QLineEdit(customWidget1);
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Accessing children

    Thank you very nuch for your suggestions, but what is this for a contruct :

    Qt Code:
    1. m_DetailInfoUI[i].LineEdit
    To copy to clipboard, switch view to plain text mode 

    Perhaps this:
    Qt Code:
    1. struct UIElements
    2. {
    3. QLineEdit* LineEdit
    4. ....
    5. ....
    6. };
    7.  
    8. QVector <UIElements> m_DetailInfoUI;
    To copy to clipboard, switch view to plain text mode 

    Am I right??

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

    Default Re: Accessing children

    That'll definitely work.

  7. #7
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Accessing children

    Thanx I will try

Similar Threads

  1. Only get children
    By wirasto in forum Newbie
    Replies: 1
    Last Post: 24th January 2010, 17:15
  2. StyleSheets and children
    By spraff in forum Qt Programming
    Replies: 2
    Last Post: 26th November 2008, 19:00
  3. How do I get the children of a layout?
    By ksierens in forum Qt Programming
    Replies: 1
    Last Post: 25th January 2008, 14:57
  4. children()
    By vermarajeev in forum Qt Programming
    Replies: 2
    Last Post: 14th May 2007, 15:15
  5. QTreeView and QStandardModel : add children
    By Valheru in forum Newbie
    Replies: 7
    Last Post: 19th September 2006, 17:24

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.