Results 1 to 10 of 10

Thread: QStringList problem :/

  1. #1
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question QStringList problem :/

    See how it goes, I have a pushButton and a lineEdit. When the pushbutton is clicked a FileDialog::getOpenFileNames pop-ups, then I want to put the files selected into the lineEdit:
    Qt Code:
    1. path = QFileDialog::getOpenFileNames(this, tr("Files & Directories"), QDir::currentPath(), tr("All files *.*") );
    2. int x = path.length();
    3. // ui->lineEdit_6->setText(path[x] + ", " + path[x-1); [B]?????????[/B]
    To copy to clipboard, switch view to plain text mode 
    I have the number of files selected but idk exactly how to put them into the lineedit...

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QStringList problem :/

    deleted QStringList has operator[]

    You should use iterators to iterate the list of strings

    Or add the whole list into a string (with the delimiter you want), using join() and then use that string to setText in the lineEdit.
    Last edited by Zlatomir; 17th August 2010 at 12:30. Reason: Corrected the mistake Lykurg mentioned

  3. #3
    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: QStringList problem :/

    Quote Originally Posted by Zlatomir View Post
    QStringList does not have the operator[]
    It has: QStringList = QList<QString> => QList::operator[].

    But I would prefere at() or value(). And in your case the suggested join() should be perfect.

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

    Zlatomir (17th August 2010)

  5. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QStringList problem :/

    @Lykurg: Thanks for correction, i'm used to c++ list (linked list) and keep forgetting that QList is implemented differently than QLinkedList (witch doesn't have [])

  6. #5
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Re: QStringList problem :/

    So, join() appends QStrings?
    How do I use it?

  7. #6
    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: QStringList problem :/

    Quote Originally Posted by hakermania View Post
    How do I use it?
    By reading the documentation or simply try?

  8. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QStringList problem :/


  9. #8
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QStringList problem :/

    Qt Code:
    1. QString l = "";
    2. path.join(l + ", ");
    3. ui->lineEdit_6->setText(l);
    To copy to clipboard, switch view to plain text mode 
    doesn't workkkkkkkk
    I am a beginner actually...
    Can you help me on this?

  10. #9
    Join Date
    Aug 2007
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QStringList problem :/

    I haven't tried it out, but reading the doc, I think you need to do:

    Qt Code:
    1. QString l = path.join(", ");
    2. ui->lineEdit_6->setText(l);
    To copy to clipboard, switch view to plain text mode 

    See if that works.
    bepaald

  11. #10
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QStringList problem :/

    Quote Originally Posted by bepaald View Post
    I haven't tried it out, but reading the doc, I think you need to do:

    Qt Code:
    1. QString l = path.join(", ");
    2. ui->lineEdit_6->setText(l);
    To copy to clipboard, switch view to plain text mode 

    See if that works.
    bepaald
    Yep, thank you!

Similar Threads

  1. qstringlist problem
    By stella1016 in forum Qt Programming
    Replies: 4
    Last Post: 17th December 2009, 09:16
  2. problem clear QStringList
    By jaca in forum Newbie
    Replies: 4
    Last Post: 30th May 2008, 16:10
  3. QStringList
    By jaca in forum Qt Programming
    Replies: 5
    Last Post: 17th May 2008, 10:12
  4. QStringList scope problem
    By ht1 in forum Qt Programming
    Replies: 5
    Last Post: 30th November 2007, 19:44
  5. Replies: 7
    Last Post: 2nd June 2006, 12:48

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.