Hi all
I m working on Qt3.1(Linux Operating System)
I m creating a linkedlist of items (id,name)
I had created the linked list of items but
I want to display the items of the created linked list in QListBox
How can i ?
Please help
Thanx
Hi all
I m working on Qt3.1(Linux Operating System)
I m creating a linkedlist of items (id,name)
I had created the linked list of items but
I want to display the items of the created linked list in QListBox
How can i ?
Please help
Thanx
Always Believe in Urself
Merry
You could use QListBox::insertItem ( const QString & text, int index = -1 )
where 'text' can be a id+name concated in one QString
Thanx for the reply
but it wont works
QListBox::insertItem ( const QString & text, int index = -1 )- How?'text' can be a id+name concated in one QString
Actually the items I had taken are char *name , int id
Last edited by merry; 13th March 2007 at 13:18. Reason: missing [code] tags
Always Believe in Urself
Merry
Thanx 4 the Reply Mr Rajeev
But where can I convert char into QString;
I m sending you the code pls View this code and tell me the solution
Qt Code:
#include <qlistbox.h> #include <qpushbutton.h> #include <qstring.h> struct list { list * next; int id; char *name; } * firstptr ; list *lastptr; void Form1::create_list() { AppendIntoList(1,"neha"); AppendIntoList(2,"jyoti"); AppendIntoList(3,"aarti"); AppendIntoList(4,"promila"); } void Form1 :: AppendIntoList(int id1,char * name1) { list * temp; if(firstptr==NULL) { firstptr=new list; firstptr->id=id1; firstptr->name=name1; firstptr->next=NULL; } else { lastptr=firstptr ; while(lastptr->next!=NULL) lastptr=lastptr->next; temp=new list; temp->id=id1; temp->name=name1; temp->next=NULL; lastptr->next=temp; } }To copy to clipboard, switch view to plain text mode
Thanx
Last edited by wysota; 14th March 2007 at 07:06. Reason: changed [quote] to [code]
Always Believe in Urself
Merry
First: it looks like you need first to learn programming with C/C++ in general.
Only then I suggest you should try working with Qt.
Basic casting problems and general C/C++ programming questions might be better suited in the general programming forum.
To the problem:
If there is no reason not to do it, you can change your struct:
This will free you from the need to cast.Qt Code:
struct list { list * next; int id; QString name; } * firstptr ;To copy to clipboard, switch view to plain text mode
If you cant do the above, then in the function where you are puting the items in the listbox you do:
Qt Code:
strItem += " "+list->name; listBox->insertItem(strItem);To copy to clipboard, switch view to plain text mode
P.S
Please use the code qutes for code, not the text quotes, thanks.
merry (13th March 2007)
Why create linked link when you already have a QPtrList provided by Qt. Is there any particular use????
Hi Rajeev
I m new to Qt and learning Qt , So my senior told me that u have to create a linklist of 4 or 5 items and also to show the created linklistt in the listbox. thats why i m using this.Why create linked link when you already have a QPtrList provided by Qt.
Always Believe in Urself
Merry
merry (14th March 2007)
Thanx 4 the advice Rajeev
Always Believe in Urself
Merry
Bookmarks