Results 1 to 17 of 17

Thread: QStringList to QTextStream

  1. #1
    Join Date
    Jan 2012
    Posts
    12
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default QStringList to QTextStream

    Hello guys,

    I've been having problems exporting source to a QTextStream using a QStringList.

    This is my code trying to export;

    Qt Code:
    1. Something
    2. Something Two
    To copy to clipboard, switch view to plain text mode 

    And i've got;

    Qt Code:
    1. S O M E T H I N G .... etc...
    To copy to clipboard, switch view to plain text mode 

    This is my code;

    Qt Code:
    1. for (int j = 0; j < TalkList[i].Script_t.size(); j++)
    2. {
    3. luaTxt << QString("\t\t%1").arg(TalkList[i].Script_t.at(j).toLocal8Bit().constData());
    4. //luaTxt << TalkList[i].Script_t.value();
    5. }
    To copy to clipboard, switch view to plain text mode 

    Script_t is a QStringList
    I'm trying to parse the lines one by one to the textstream with 2 initial tabs (\t\t) but result is strange.

    Please help me it's 6:53 and I've 2 hours trying to solve it

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

    Default Re: QStringList to QTextStream

    What is the type of TalkList.Script_t?
    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
    Jan 2012
    Posts
    12
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QStringList to QTextStream

    I've said in the post it; Script_t is a QStringList

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

    Default Re: QStringList to QTextStream

    What happens if you do this?

    Qt Code:
    1. luaTxt << QString("\t\t%1").arg(TalkList[i].Script_t.at(j));
    To copy to clipboard, switch view to plain text mode 
    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.


  5. #5
    Join Date
    Jan 2012
    Posts
    12
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QStringList to QTextStream

    I get the same, each characterin the file is separated with the 2 tabs which shouldn't be happening.

    I'm trying to add all of the lines with 2 tabs in the very beginning, but seems i've been not allowed to do this.

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

    Default Re: QStringList to QTextStream

    ok, what does this print?
    Qt Code:
    1. qDebug() << TalkList[i].Script_t;
    To copy to clipboard, switch view to plain text mode 
    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.


  7. #7
    Join Date
    Jan 2012
    Posts
    12
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QStringList to QTextStream

    Quote Originally Posted by wysota View Post
    ok, what does this print?
    Qt Code:
    1. qDebug() << TalkList[i].Script_t;
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. ("l", "o", "c", "a", "l", " ", "m", "y", "V", "a", "r", " ", "=", " ", "1", "0", "0", "0", "
    2. ", "n", "p", "c", "H", "a", "n", "d", "l", "e", "r", ":", "s", "a", "y", "(", "m", "y", "V", "a", "r", ",", " ", "c", "i", "d", ")", "
    3. ", "n", "p", "c", "H", "a", "n", "d", "l", "e", "r", ":", "r", "e", "l", "e", "a", "s", "e", "F", "o", "c", "u", "s", "(", "c", "i", "d", ")")
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: QStringList to QTextStream

    Apparently your stringlist is incorrect. How did you create 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.


  9. #9
    Join Date
    Jan 2012
    Posts
    12
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QStringList to QTextStream

    item.Script_t = ui->textEdit->toPlainText();

    I've tried at(i) and still same results.

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

    Default Re: QStringList to QTextStream

    toPlainText() returns QString and not QStringList. So is it QString or QStringList? Is the code you posted your actual code or "sort of" your code?
    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.


  11. #11
    Join Date
    Jan 2012
    Posts
    12
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QStringList to QTextStream

    It is my code.

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

    Default Re: QStringList to QTextStream

    So is it QString or QStringList? If it's QStringList then the code shouldn't compile.
    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.


  13. #13
    Join Date
    Jan 2012
    Posts
    12
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QStringList to QTextStream

    Script_t is QStringList and it compiles on my VS2010.

  14. #14
    Join Date
    Jan 2008
    Posts
    72
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: QStringList to QTextStream

    Wysota is right , toPlainText() returns QString and not QStringList. So access your each value ,split that string into a stringlist..

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

    Default Re: QStringList to QTextStream

    Quote Originally Posted by Jonathan Maen View Post
    Script_t is QStringList and it compiles on my VS2010.
    Please check that as the application behaves as if it were not a string list.
    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.


  16. #16
    Join Date
    Jan 2012
    Posts
    12
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QStringList to QTextStream

    So It's been a few days since I've got this problem, and since I'm just 17 years old, and just 2 weeks with C++ and Qt, I'm just learning.

    What's the best way to parse each line of QTextEdit into a QStringList, I really need this in order to add 2 tabs to the beginning of every line of the file.

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

    Default Re: QStringList to QTextStream

    The most basic approach I can think of is:
    Qt Code:
    1. QStringList lines = textEdit->toPlainText().split("\n");
    To copy to clipboard, switch view to plain text mode 

    However that's probably not the best possible way. It would be much better (albeit more complicated) to use QTextDocument API.
    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.


  18. The following user says thank you to wysota for this useful post:

    Jonathan Maen (2nd February 2012)

Similar Threads

  1. Help QStringList
    By pcoliver in forum Qt Programming
    Replies: 0
    Last Post: 15th September 2011, 10:15
  2. Plz help me,I met a bug about QStringList
    By study_c in forum Qt Programming
    Replies: 1
    Last Post: 16th October 2010, 15:56
  3. Replies: 4
    Last Post: 9th August 2009, 01:04
  4. QStringList
    By jaca in forum Qt Programming
    Replies: 5
    Last Post: 17th May 2008, 10:12
  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
  •  
Qt is a trademark of The Qt Company.