Results 1 to 4 of 4

Thread: How to create a function which takes QList<QTreeWidgetItem *> and returns QStringList

  1. #1
    Join Date
    Aug 2010
    Posts
    8
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default How to create a function which takes QList<QTreeWidgetItem *> and returns QStringList

    Hi,

    I am using QTreeWidget in my application. I come across a situation where i need a function which takes QList<QTreeWidgetItem*> and returns QStringlist. I am somewhat using the code below to cast the QList<QTreeWidgetItem*> to QStringList.

    QStringList convertToStringList(QList<QTreeWidgetItem*> &items)
    {

    QStringList lines;
    lines.clear();

    for(int i=0;i<item.size();++i)
    {
    lines += static_cast<QStringList *> (item.at(i));
    }

    return lines;
    }



    I am not able to cast the QList<QTreeWidgetItem* > item to QStringList. Please help me with this.

    Thanks. Waiting for reply.

  2. #2
    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: How to create a function which takes QList<QTreeWidgetItem *> and returns QString

    Such casts are not allowed. If you want to extract the text from QTreeWidgetItem, use QTreeWidgetItem::text().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Aug 2010
    Posts
    8
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: How to create a function which takes QList<QTreeWidgetItem *> and returns QString

    Thanks, I have to perform a "Copy/Paste" task using QTreeWidgetItem I have written the code to Copy the QList<QTreeWidgetItem *> but I am facing issues in Pasting this content into the tree at any position. Canl you guide me how to do that?

  4. #4
    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: How to create a function which takes QList<QTreeWidgetItem *> and returns QString

    Please state what the problem is, your description is too generic to make up anything from it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QList QgraphicsItem pos x value returns 0
    By devdon in forum Qt Programming
    Replies: 10
    Last Post: 20th September 2011, 08:46
  2. using QStringList as QList<QListWidgetItem*>
    By geleven in forum Qt Programming
    Replies: 3
    Last Post: 8th April 2010, 18:13
  3. QStringList or QList , which is faster
    By BalaQT in forum Newbie
    Replies: 3
    Last Post: 3rd April 2010, 08:48
  4. QList/QStringList comparison question
    By di_zou in forum Newbie
    Replies: 5
    Last Post: 28th October 2009, 14:35
  5. replace string in QList<QStringList>
    By estanisgeyer in forum Qt Programming
    Replies: 2
    Last Post: 7th March 2008, 17:40

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.