Results 1 to 11 of 11

Thread: Linked List

  1. #1
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Linked List

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Linked List

    You could use QListBox::insertItem ( const QString & text, int index = -1 )
    where 'text' can be a id+name concated in one QString

  3. #3
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Linked List

    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
    Last edited by merry; 13th March 2007 at 13:18. Reason: missing [code] tags
    Always Believe in Urself
    Merry

  4. #4
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Linked List

    Quote Originally Posted by merry View Post
    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);

  5. #5
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Linked List

    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:
    1. #include <qlistbox.h>
    2. #include <qpushbutton.h>
    3. #include <qstring.h>
    4.  
    5.  
    6.  
    7. struct list
    8. {
    9. list * next;
    10. int id;
    11. char *name;
    12. } * firstptr ;
    13.  
    14. list *lastptr;
    15.  
    16.  
    17.  
    18. void Form1::create_list()
    19. {
    20.  
    21. AppendIntoList(1,"neha");
    22. AppendIntoList(2,"jyoti");
    23. AppendIntoList(3,"aarti");
    24. AppendIntoList(4,"promila");
    25. }
    26.  
    27.  
    28.  
    29.  
    30. void Form1 :: AppendIntoList(int id1,char * name1)
    31. {
    32. list * temp;
    33. if(firstptr==NULL)
    34. {
    35. firstptr=new list;
    36. firstptr->id=id1;
    37. firstptr->name=name1;
    38. firstptr->next=NULL;
    39.  
    40. }
    41. else
    42. {
    43. lastptr=firstptr ;
    44. while(lastptr->next!=NULL)
    45. lastptr=lastptr->next;
    46. temp=new list;
    47. temp->id=id1;
    48. temp->name=name1;
    49. temp->next=NULL;
    50. lastptr->next=temp;
    51. }
    52. }
    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

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Linked List

    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:
    Qt Code:
    1. struct list
    2. {
    3. list * next;
    4. int id;
    5. QString name;
    6. } * firstptr ;
    To copy to clipboard, switch view to plain text mode 
    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:
    Qt Code:
    1. QString strItem = QString::number(list->id);
    2. strItem += " "+list->name;
    3. 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.

  7. The following user says thank you to high_flyer for this useful post:

    merry (13th March 2007)

  8. #7
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Linked List

    Why create linked link when you already have a QPtrList provided by Qt. Is there any particular use????

  9. #8
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Linked List

    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.
    Always Believe in Urself
    Merry

  10. #9
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Linked List

    Quote Originally Posted by merry View Post
    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

  11. The following user says thank you to vermarajeev for this useful post:

    merry (14th March 2007)

  12. #10
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Linked List

    Thanx 4 the advice Rajeev
    Always Believe in Urself
    Merry

  13. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Linked List

    Quote Originally Posted by vermarajeev View Post
    Start learning Qt4.x.x, as Trolltech will stop supporting Qt3.x.x from June.
    Trolltech will, but we won't

Similar Threads

  1. Replies: 4
    Last Post: 11th September 2006, 14:13
  2. list of list
    By quickNitin in forum Newbie
    Replies: 1
    Last Post: 3rd July 2006, 08:11
  3. I got two problems when I used static compiled library of QT4
    By qintm in forum Installation and Deployment
    Replies: 8
    Last Post: 20th April 2006, 08:52
  4. Array of linked lists
    By therealjag in forum General Programming
    Replies: 9
    Last Post: 9th March 2006, 18:36
  5. QtCentre vs. Qt-Interest mailing list vs. QtForum?
    By brcain in forum General Discussion
    Replies: 4
    Last Post: 16th February 2006, 01:46

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.