Results 1 to 4 of 4

Thread: using QStringList as QList<QListWidgetItem*>

  1. #1
    Join Date
    Apr 2010
    Posts
    7
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Question using QStringList as QList<QListWidgetItem*>

    dear all,

    i have some problem, which is described by code below :

    Qt Code:
    1. void lists::removeList()
    2. {
    3. QStringList temp = this->readListDoc();
    4. QStringList removes = this->ui->ListPic->selectedItems();
    5. //this->ui->ListPic->clear();
    6. }
    To copy to clipboard, switch view to plain text mode 

    ListPic is a QListWidget, and the function selectedItems() suppose to return a QList<QListWidgetItem*>. The problem is i want to use QList<QListWidgetItem*> as a QStringList.

    the error give statement like this
    conversion from 'QList<QListWidgetItem*>' to non-scalar type 'QStringList' requested.

    how i can solve this problem?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: using QStringList as QList<QListWidgetItem*>

    It seems that you do some simple things very complicated... But anyway:
    Qt Code:
    1. QStringList removes;
    2. QList<QListWidgetItem*> tmpList = this->ui->ListPic->selectedItems();
    3. for (int i = 0; i < tmpList.size(); ++i)
    4. removes.append(tmpList.at(i)->text());
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Lykurg for this useful post:

    geleven (8th April 2010)

  4. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: using QStringList as QList<QListWidgetItem*>

    Hi,

    You can't. QStringList is QList<QString> and QListWidget is QList<QListWidgetItem*>. So it's impossible to convert QListWidgetItem pointers to QStrings.
    Maybe if you ask what your code is suposed to do we could help you.

  5. The following user says thank you to ^NyAw^ for this useful post:

    geleven (8th April 2010)

  6. #4
    Join Date
    Apr 2010
    Posts
    7
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: using QStringList as QList<QListWidgetItem*>

    Quote Originally Posted by Lykurg View Post
    It seems that you do some simple things very complicated... But anyway:
    Qt Code:
    1. QStringList removes;
    2. QList<QListWidgetItem*> tmpList = this->ui->ListPic->selectedItems();
    3. for (int i = 0; i < tmpList.size(); ++i)
    4. removes.append(tmpList.at(i)->text());
    To copy to clipboard, switch view to plain text mode 
    woah... it's that simple.. it seems i thinking too far away.. thanks for the help

Similar Threads

  1. QStringList or QList , which is faster
    By BalaQT in forum Newbie
    Replies: 3
    Last Post: 3rd April 2010, 08:48
  2. QList/QStringList comparison question
    By di_zou in forum Newbie
    Replies: 5
    Last Post: 28th October 2009, 14:35
  3. replace string in QList<QStringList>
    By estanisgeyer in forum Qt Programming
    Replies: 2
    Last Post: 7th March 2008, 17:40
  4. Casting QStringList to QList<QVariant>
    By Valheru in forum Newbie
    Replies: 3
    Last Post: 5th October 2006, 22:24
  5. Replies: 7
    Last Post: 2nd June 2006, 12:48

Tags for this Thread

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.