Results 1 to 18 of 18

Thread: ASCII Number to Strings & Chars

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2012
    Posts
    47
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: ASCII Number to Strings & Chars

    i want it to appear on a lineedit,
    ui->lineEdit->setText(s);
    ui->lineEdit->setText(result);
    neither works
    error: no matching function for call to 'QLineEdit::setText(QStringList&)'

    and, i'm newbie. do i need to use this codes 3 times? the QStringList is aaab, bbc or cde or all?

    (im using gui, so qDebug() wont work here right?)

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ASCII Number to Strings & Chars

    lineedit is for showing one string.

    if you want to show string on multiple lines then use a textedit
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Nov 2012
    Posts
    47
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: ASCII Number to Strings & Chars

    i want the first string (AAA) to show on aLine;
    2nd string (BBC) to show on bLine;
    3rd string (CDE) to show on cLine;

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ASCII Number to Strings & Chars

    so look at QStringList documents and figure out how you can get first string out from it. Then think about the rest
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: ASCII Number to Strings & Chars

    It is an example, not a cut and paste solution.

    QStringList, as the name implies, is a QList of QStrings. Like any QList you can access one of the elements using QList::at(). Your three strings are the first three elements in the list, i.e. 0, 1, and 2.

    As a newbie you should learn where to find Qt Assistant, or the Help in Qt Creator, and read it.

  6. #6
    Join Date
    Nov 2012
    Posts
    47
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: ASCII Number to Strings & Chars

    well, sometimes the help does not provide example its hard to understand.

    Qt Code:
    1. QStringList result;
    2. QFile input("configp.dll");
    3. if (input.open(QIODevice::ReadOnly)) {
    4. while (!input.atEnd()) {
    5. QByteArray line = input.readLine().trimmed();
    6.  
    7. foreach(QByteArray num, line.split(' ')) {
    8. s.append( QChar(num.toShort()) );
    9.  
    10. }
    11. result << s;
    12. ui->aLine->setText(result::at(1));
    13. }
    14. }else
    To copy to clipboard, switch view to plain text mode 
    runtime error

    if changed to
    ui->aLine->setText(result.QList::at(1));
    ERROR : template<class T> class QList' used without template parameters
    Last edited by ttimt; 28th November 2012 at 08:25.

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

    Default Re: ASCII Number to Strings & Chars

    Quote Originally Posted by ttimt View Post
    well, sometimes the help does not provide example its hard to understand.
    The help is not an almanach of examples, it's a means to learn how things work by reading it and applying the knowledge gained in practise in your own code.

    The error you got is a C++ error, Qt help has nothing to do with this. When you get that fixed, analyze your code and think what will be the ultimate result of your code. I'll simplify it for you so it's easier to read:

    Qt Code:
    1. QStringList result;
    2. result << "something" << "somethingelse";
    3. while(!input.atEnd()) {
    4. ui->aLine->setText(result.at(1));
    5. }
    To copy to clipboard, switch view to plain text mode 

    Please focus on subsequent iterations of the while loop.
    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.


  8. #8
    Join Date
    Nov 2012
    Posts
    47
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: ASCII Number to Strings & Chars

    hmmm.... it seems the problem is QStringList results have nothing in it? Hopefully im right
    And when i use canReadLine(), the program actually outputted cant read line

    Qt Code:
    1. QStringList result;
    2. result << "Something" << "abc";
    3. QFile input("configp.dll");
    4.  
    5. if (input.open(QIODevice::ReadOnly )) {
    6.  
    7. if(input.canReadLine()){
    8.  
    9. ui->hLine->setText("can read");
    10.  
    11. }else{
    12.  
    13. //EDITED : removed this line QApplication::processEvents();
    14. ui->hLine->setText("cant read line"); //outputted this " can't read line "
    15. }
    16.  
    17. while (!input.atEnd()){
    18.  
    19. QByteArray line = input.readLine().simplified(); //trimmed to simplified
    20. QString foo; //actually which line of code chris provided converted ascii numbers to char?
    21.  
    22. foreach(QByteArray num, line.split(' ')) {
    23. foo.append( QChar(num.toShort()) ); // is it this .toShort?
    24. }
    25. result << foo;// if use line->setText() here also output same..
    26. }
    27. ui->aLine->setText(result.at(0)); // this output Something
    28.  
    29. ui->fLine->setText(result.at(1)); //this output abc not anything from the file
    To copy to clipboard, switch view to plain text mode 


    Edited : if i add these code below, it actually shows "can read"

    Qt Code:
    1. if (input.open(QIODevice::ReadOnly )) {
    2. char c;
    3. input.getChar(&c);
    4. if(input.canReadLine()){
    5. ui->hLine->setText("can read");
    6. }else{
    7. ui->hLine->setText("cant read line");
    8. }
    To copy to clipboard, switch view to plain text mode 

    EDITED: AND HEY, AFTER HOURS OF CODING, I MANGED TO LET IT shows up on aLine But (didn't know i put it inside while loop)after showing up, it still goes runtime error, so i guess i gonna figure out what wysota(hope i spell it correct) is saying

    EDITED: I actually found i duplicated settext that caused error. it's working now but figuring out how to output only available line. By the way, will moderator ban for too many edits? I still have some problems with rename. qdir wont work too

    EDITED: it now shows runtime error again.
    EDITED: i actually jumped setText() from 0 to 3 where i only wanna jump 0 to 2, NOTE the rename still doesn't work

    Qt Code:
    1. QFile chk("configp.dll");
    2. chk.open(QIODevice::ReadOnly);
    3. if(chk.exists()){
    4.  
    5. QFile exs("configp1.dll");
    6. if(exs.open(QIODevice::ReadOnly))
    7. exs.remove(); //this can delete, works very well
    8.  
    9.  
    10. chk.rename("configp1.dll"); // it wont rename
    11.  
    12. }else{
    To copy to clipboard, switch view to plain text mode 
    Last edited by ttimt; 28th November 2012 at 17:26.

Similar Threads

  1. qgetenv and special chars
    By miraks in forum Qt Programming
    Replies: 8
    Last Post: 24th October 2020, 01:05
  2. Replies: 1
    Last Post: 5th March 2012, 06:34
  3. QTextEdit 80 chars wide
    By mpi in forum Qt Programming
    Replies: 4
    Last Post: 29th January 2011, 13:18
  4. Static casting of signed chars
    By ShamusVW in forum Qt Programming
    Replies: 0
    Last Post: 4th November 2009, 05:46
  5. Need help. can't append chars in QString
    By AcerExtensa in forum Qt Programming
    Replies: 6
    Last Post: 12th June 2008, 10:57

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.