View Full Version : Linked List
merry
13th March 2007, 13:52
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
high_flyer
13th March 2007, 14:00
You could use QListBox::insertItem ( const QString & text, int index = -1 )
where 'text' can be a id+name concated in one QString
merry
13th March 2007, 14:16
Thanx for the reply
but it wont works
QListBox::insertItem ( const QString & text, int index = -1 )
'text' can be a id+name concated in one QString - How?
Actually the items I had taken are char *name , int id
vermarajeev
13th March 2007, 14:24
Thanx for the reply
but it wont works
- How?
Actually the items I had taken are char *name , int id
convert char* name to QString like this
QString nameStr(name);
merry
13th March 2007, 14:36
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
#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;
}
}
Thanx
high_flyer
13th March 2007, 14:56
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:
struct list
{
list * next;
int id;
QString name;
} * firstptr ;
This will free you from the need to cast.
If you cant do the above, then in the function where you are puting the items in the listbox you do:
QString strItem = QString::number(list->id);
strItem += " "+list->name;
listBox->insertItem(strItem);
P.S
Please use the code qutes for code, not the text quotes, thanks.
vermarajeev
14th March 2007, 04:28
Why create linked link when you already have a QPtrList provided by Qt. Is there any particular use????
merry
14th March 2007, 05:38
Hi Rajeev
Why create linked link when you already have a QPtrList provided by Qt.
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.
vermarajeev
14th March 2007, 06:13
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.
Start learning Qt4.x.x, as Trolltech will stop supporting Qt3.x.x from June. I too have to uninstall Qt3.x.x and start using Qt4...
Thanks
merry
14th March 2007, 06:30
Thanx 4 the advice Rajeev
wysota
14th March 2007, 08:07
Start learning Qt4.x.x, as Trolltech will stop supporting Qt3.x.x from June.
Trolltech will, but we won't :)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.