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

    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.