×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Regular Contributor
    Join Date
    Aug 2009
    Posts
    331

    How to add items dynamically to QListWidget?

    Hi,

    I want to add items dynamically to QListWidget in Qt.

    I have used the following piece of code to add items dynamically, but I am able to add only one item in QListWidget...

    Code:
     for(int i=0; i<5; i++)
                {
                   
                    structLocationDetails[i].strlocationName = metaresult["locationName"];
        
        
                    QString strtemp = structLocationDetails[i].strlocationName;
        
                    
                    list=new QListWidget(this);
                    list->setSortingEnabled(true);
        
                    list->setGeometry(0,0,190, 450);
                    QStringList items;
        
                    item1=new QListWidgetItem(QIcon(":/imagesIcon.png"),structLocationDetails[i].strlocationName,list);
        
                    connect(list,SIGNAL(itemClicked(QListWidgetItem*)),this,SLOT(myitem(QListWidgetItem*)));
        
                }
    Here actually I am parsing an XML file and trying to add the parsed xml file contents(locationName) to the QListWidget.

    How can I achieve this?

    Any suggestions on this...!

    Thanks...

  2. #2
    Super Contributor
    Join Date
    Nov 2004
    Posts
    1,009
    Regards,
    Shafali

  3. #3
    Regular Contributor
    Join Date
    Aug 2009
    Posts
    331

    Re: How to add items dynamically to QListWidget?

    Hey I tried as per the links...

    Used Link1:
    for(int i=0; i<5; i++)
    {
    structLocationDetails[i].strlocationName = metaresult["locationName"];
    QString strtemp = structLocationDetails[i].strlocationName;
    list=new QListWidget(this);
    list->setSortingEnabled(true);
    list->setGeometry(0,0,190, 450);
    list->insertItem(i+1, structLocationDetails[i].strlocationName);
    connect(list,SIGNAL(itemClicked(QListWidgetItem*)),this,SLOT(myitem(QListWidgetItem*)));
    }
    used Link2:
    for(int i=0; i<5; i++)
    {
    structLocationDetails[i].strlocationName = metaresult["locationName"];
    QString strtemp = structLocationDetails[i].strlocationName;
    list=new QListWidget(this);
    list->setSortingEnabled(true);
    list->setGeometry(0,0,190, 450);
    item1=new QListWidgetItem(QIcon(":/images/Icon.png"),structLocationDetails[i].strlocationName,list);
    list->addItem(item1);
    connect(list,SIGNAL(itemClicked(QListWidgetItem*)),this,SLOT(myitem(QListWidgetItem*)));
    }
    In both cases only the second item is added like i had mentioned in my very first post, and the first item is missed to add?
    Why is it so?

    Thanks...

  4. #4
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to add items dynamically to QListWidget?

    Code:
    list=new QListWidget(this);
    list->setSortingEnabled(true);
    connect(list,SIGNAL(itemClicked(QListWidgetItem*)),this,SLOT(myitem(QListWidgetItem*)));
    for(int i=0; i<5; ++i) {
        structLocationDetails[i].strlocationName = metaresult["locationName"];
        QListWidgetItem *item=new QListWidgetItem(QIcon(":/images/Icon.png"),structLocationDetails[i].strlocationName);
        list->addItem(item);
    }

  5. #5
    Regular Contributor
    Join Date
    Aug 2009
    Posts
    331

    Re: How to add items dynamically to QListWidget?

    Thanks,
    It was totally my fault...

    Everytime I was creating the list...

    thanks a lot...

  6. #6
    Registered User
    Join Date
    Jan 2009
    Location
    ભારત->ગુજરાત->ભાવનગર
    Posts
    279

    Question Re: How to add items dynamically to QListWidget?

    hi Rajeev
    i think your problem of adding dynamically items to Qlistwidget is solved...i am also faicing the same problem.
    I have gone throught post but i am unable to understand this line
    [
    Code:
    structLocationDetails[i].strlocationName = metaresult["locationName"];
    ]

    here what is structLocation,strLocation??
    Regards
    Viral Parmar

  7. #7
    Regular Contributor
    Join Date
    Aug 2009
    Posts
    331

    Re: How to add items dynamically to QListWidget?

    Quote Originally Posted by mind_freak View Post
    hi Rajeev
    i think your problem of adding dynamically items to Qlistwidget is solved...i am also faicing the same problem.
    I have gone throught post but i am unable to understand this line
    [
    Code:
    structLocationDetails[i].strlocationName = metaresult["locationName"];
    ]

    here what is structLocation,strLocation??
    Hey..
    As per my project requirement I have created a Structure i.e. "structLocationDetails" and "strlocationName" is the structure element.
    I am just parsing the XML contents and saving the data in those structure elements.

    Nothing else.

    I hope you got it right.

    Thanks

Similar Threads

  1. How to add items in listbox dynamically!!
    By ssabestian in forum Symbian
    Replies: 6
    Last Post: 2009-02-20, 16:06
  2. How to Add menu items dynamically?
    By marvik_34 in forum Symbian User Interface
    Replies: 10
    Last Post: 2008-06-24, 03:27
  3. add items dynamically to listbox
    By AbuElElla in forum Symbian
    Replies: 2
    Last Post: 2005-07-18, 13:47
  4. Replies: 0
    Last Post: 2004-11-24, 07:56
  5. Replies: 1
    Last Post: 2002-08-19, 14:28

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×