Results 1 to 6 of 6

Thread: Ascii problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2007
    Location
    Netherlands
    Posts
    54
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Ascii problem

    Hey

    I have a problem with a program i am trying to create. For the program i need to read a file and convert what i read to ascii codes so i can manipulate it. I have suceded into reading the file and converting a part of the data to ascii values but at some characters i get 0 values. The file i test it with is a file i created with a hex editer in which i typed al the hex values from 0 to FF. The problem lies in the extended ascii characters. I have attached my test file i is a simple file with no extension.

    Here is the code i use:
    Qt Code:
    1. #include <QApplication>
    2. #include <QtGui>
    3. #include "yenc.h"
    4.  
    5. Yenc::Yenc(QWidget *parent)
    6. : QDialog(parent)
    7. {
    8.  
    9. QPushButton *connect = new QPushButton("Hello Qt!");
    10. QPushButton *list = new QPushButton("Hello Qt!");
    11. lineEdit = new QLineEdit;
    12. textbox = new QTextEdit("test");
    13.  
    14. QObject::connect(connect, SIGNAL(clicked()), this, SLOT(buttonClicked()));
    15. QObject::connect(list, SIGNAL(clicked()), this, SLOT(textboxClear()));
    16.  
    17. QHBoxLayout *layout = new QHBoxLayout;
    18.  
    19. layout->addWidget(connect);
    20. layout->addWidget(list);
    21. layout->addWidget(lineEdit);
    22. layout->addWidget(textbox);
    23. setLayout(layout);
    24. setWindowTitle(tr("Test"));
    25. }
    26.  
    27. int Yenc::buttonClicked()
    28. {
    29. QString readstring;
    30. qint64 asciival;
    31.  
    32. QFile file(lineEdit->text());
    33. if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
    34. {
    35. return 0;
    36. }
    37.  
    38. QTextStream out(&file);
    39.  
    40. while(!out.atEnd())
    41. {
    42. readstring = out.read(1);
    43. asciival = readstring.at(0).toAscii();
    44.  
    45. if(asciival < 0)
    46. {
    47. asciival = asciival + 256;
    48. }
    49.  
    50. textbox->append(QString::number(asciival));
    51. }
    52. }
    53.  
    54. int Yenc::textboxClear()
    55. {
    56. textbox->clear();
    57. }
    To copy to clipboard, switch view to plain text mode 

    Hope someone can help me

    Thanks
    Marcel
    Attached Files Attached Files

Similar Threads

  1. Unicode problem in hoverlink
    By anju123 in forum Qt Programming
    Replies: 2
    Last Post: 27th August 2007, 13:56
  2. [QMYSQL] connection problem
    By chaos_theory in forum Installation and Deployment
    Replies: 5
    Last Post: 2nd July 2007, 09:52
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15: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.