Results 1 to 3 of 3

Thread: Dynamic number of QLabel

  1. #1
    Join Date
    Feb 2008
    Posts
    21
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Dynamic number of QLabel

    Hello,

    I have a problem to create a dynamic number of QLabel and QLineEdit.

    I have build a QList:

    Qt Code:
    1. QList<QLineEdit*> dongleDataLineEdit;
    2. QList<QLabel*> dongleDataLabel;
    To copy to clipboard, switch view to plain text mode 

    Now, the code to generate my QLabel an QLineEdit.

    Qt Code:
    1. void CMainWindow::setDongleDataField() {
    2. for (int i=0; i<plainDongle->DNG_Memmory/4; i++) {
    3. dongleDataLabel.append(new QLabel);
    4. dongleDataLineEdit.append(new QLineEdit);
    5. }
    6.  
    7. displayDongleData();
    8. }
    9.  
    10. void CMainWindow::displayDongleData() {
    11. QGridLayout *dongleLayout = new QGridLayout;
    12. int x = 0;
    13.  
    14. for (int i; i<plainDongle->DNG_Memmory/4; i++) {
    15. dongleDataLabel[i]->setText(tr("Value "+i));
    16. dongleLayout->addWidget(dongleDataLabel[i], x, 0);
    17. dongleLayout->addWidget(dongleDataLineEdit[i], x, 1);
    18. x++;
    19. }
    20. }
    To copy to clipboard, switch view to plain text mode 

    The problem is, my program does not start, it terminated without any error.

    Can someone help me to fix the problem?
    The most difficult in the world is to live in it

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Dynamic number of QLabel

    Quote Originally Posted by jd View Post
    Qt Code:
    1. void CMainWindow::displayDongleData() {
    2. QGridLayout *dongleLayout = new QGridLayout;
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. QGridLayout *dongleLayout = new QGridLayout(this);
    To copy to clipboard, switch view to plain text mode 
    and is CMainWindow shown? What is CMainWindow? have you called "app.exec()" in main?
    Quote Originally Posted by jd View Post
    Qt Code:
    1. int x = 0;
    2.  
    3. for (int i; i<plainDongle->DNG_Memmory/4; i++) {
    4. dongleDataLabel[i]->setText(tr("Value "+i));
    5. dongleLayout->addWidget(dongleDataLabel[i], x, 0);
    6. dongleLayout->addWidget(dongleDataLineEdit[i], x, 1);
    7. x++;
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 
    You don't need "int x" just use "i". And better use "i<dongleDataLabel.size()"

    EDIT: once you have "dongleDataLabel." and once "dongleDataLabel->"? but that must result in an compiler error...
    Last edited by Lykurg; 4th April 2008 at 18:05. Reason: updated contents

  3. #3
    Join Date
    Feb 2008
    Posts
    21
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Dynamic number of QLabel

    Argh!

    The mistake was her:
    Qt Code:
    1. for (int i; i<plainDongle->DNG_Memmory/4; i++) {
    To copy to clipboard, switch view to plain text mode 

    i has no value...

    so my program starts, but i have another problem with my layout.

    If i call
    Qt Code:
    1. setLayout(dongleLayout);
    To copy to clipboard, switch view to plain text mode 

    I become an error, wicht a layout is already set. How can I add my dongleLayout to CMainWindow?

    CMainWindow is my QMainWindow I've created this with QtDesigner.
    I can't found a function addLayout.

    The error:
    QWidget::setLayout: Attempting to add QLayout "" to QWidget "layoutWidget", which already has a layout
    The most difficult in the world is to live in it

Similar Threads

  1. QLabel ScaledContents ignored by style sheet?
    By WinchellChung in forum Newbie
    Replies: 3
    Last Post: 27th February 2008, 15:50
  2. QLabel size policy
    By Caius Aérobus in forum Qt Programming
    Replies: 3
    Last Post: 7th December 2007, 18:57
  3. Line Number - QTextEdit...???
    By deepusrp in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2007, 17:34
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 07:13
  5. Replies: 6
    Last Post: 5th March 2006, 22:05

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.