December 19, 2010

endla.ravi endla.ravi
Lab Rat
17 posts

Unable to display items of QListWidget

 

Hi…

I have a problem in displaying the QListWidget ..

When i have create the QListWidget from the drag and drop menu..and used like this

  1. ui->listWidget->addItem("Hello")

,its working fyn and displaying int the form when i execute.

But if i do the same in this manner,

  1. QListWidgetItem q1=new QListWidgetItem("hello",list,i);
  2.  
  3. ui->listWidgetItem->addItem(q1);  

The above code compiles with no errors,but in the list widget i am unable to find the item.

Does anyone please sort out this problem..

Thanks in advance….

edit: Code highlighting / Vass

10 replies

December 19, 2010

Vass Vass
Hobby Entomologist
738 posts

You forgot * before pointer variable(before q1 variable)

 Signature 


Vasiliy

December 19, 2010

VCsala VCsala
Lab Rat
339 posts

I was thinking on the same but I am really suprised that it provides clean compile…

December 19, 2010

Vass Vass
Hobby Entomologist
738 posts
VCsala wrote:
I was thinking on the same but I am really suprised that it provides clean compile…

Me too, I tested it just. My compiler said:

conversion from ‘QListWidgetItem*’ to non-scalar type ‘QListWidgetItem’ requested

 Signature 


Vasiliy

December 19, 2010

endla.ravi endla.ravi
Lab Rat
17 posts

i forgot to put a * there,i actually put it in my program,missed it out here..

it is

  1. QListWidgetItem *q1=new QListWidgetItem(“hello”,list,i);

edit: Code highlighting / Vass

December 19, 2010

VCsala VCsala
Lab Rat
339 posts

It is a good idea (at least for the next time) to use ‘@’ around your code which makes syntax highlighted and more readable.

December 19, 2010

VCsala VCsala
Lab Rat
339 posts
endla.ravi wrote:
ui->listWidgetItem->addItem(q1);

Is this correct (listWidgetItem or listWidget)?

December 19, 2010

Vass Vass
Hobby Entomologist
738 posts

Show more code, please.
I don’t understand, what is , what is list, why you set parent list, but adding item to ui->listWidget

 Signature 


Vasiliy

December 19, 2010

VCsala VCsala
Lab Rat
339 posts

I think this should look something like this:

  1. QListWidgetItem *q1 = new QListWidgetItem("hello", ui->listWidget);

And, according to the documentation, this will add the item to the list too, so it is not required to call the addItem.

If you have a sorted list, the above line has an undeterministic behaviour. In this case set the second paramater (parent) of the constructor to 0 and use ui->listWidget->insertItem(…) to insert the new item.

December 19, 2010

endla.ravi endla.ravi
Lab Rat
17 posts

@all,thanQ..

I sorted out the problem..

December 19, 2010

VCsala VCsala
Lab Rat
339 posts

Maybe it is a good idea to share what was the issue and how you have solved it.

 
  ‹‹ How do I "move" an item from one QListWidget to another?      Crash-Segmentation fault ››

You must log in to post a reply. Not a member yet? Register here!