eekhoorn12
15th October 2007, 22:45
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:
#include <QApplication>
#include <QtGui>
#include "yenc.h"
Yenc::Yenc(QWidget *parent)
: QDialog(parent)
{
QPushButton *connect = new QPushButton("Hello Qt!");
QPushButton *list = new QPushButton("Hello Qt!");
lineEdit = new QLineEdit;
textbox = new QTextEdit("test");
QObject::connect(connect, SIGNAL(clicked()), this, SLOT(buttonClicked()));
QObject::connect(list, SIGNAL(clicked()), this, SLOT(textboxClear()));
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(connect);
layout->addWidget(list);
layout->addWidget(lineEdit);
layout->addWidget(textbox);
setLayout(layout);
setWindowTitle(tr("Test"));
}
int Yenc::buttonClicked()
{
QString readstring;
qint64 asciival;
QFile file(lineEdit->text());
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
return 0;
}
QTextStream out(&file);
while(!out.atEnd())
{
readstring = out.read(1);
asciival = readstring.at(0).toAscii();
if(asciival < 0)
{
asciival = asciival + 256;
}
textbox->append(QString::number(asciival));
}
}
int Yenc::textboxClear()
{
textbox->clear();
}
Hope someone can help me
Thanks
Marcel
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:
#include <QApplication>
#include <QtGui>
#include "yenc.h"
Yenc::Yenc(QWidget *parent)
: QDialog(parent)
{
QPushButton *connect = new QPushButton("Hello Qt!");
QPushButton *list = new QPushButton("Hello Qt!");
lineEdit = new QLineEdit;
textbox = new QTextEdit("test");
QObject::connect(connect, SIGNAL(clicked()), this, SLOT(buttonClicked()));
QObject::connect(list, SIGNAL(clicked()), this, SLOT(textboxClear()));
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(connect);
layout->addWidget(list);
layout->addWidget(lineEdit);
layout->addWidget(textbox);
setLayout(layout);
setWindowTitle(tr("Test"));
}
int Yenc::buttonClicked()
{
QString readstring;
qint64 asciival;
QFile file(lineEdit->text());
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
return 0;
}
QTextStream out(&file);
while(!out.atEnd())
{
readstring = out.read(1);
asciival = readstring.at(0).toAscii();
if(asciival < 0)
{
asciival = asciival + 256;
}
textbox->append(QString::number(asciival));
}
}
int Yenc::textboxClear()
{
textbox->clear();
}
Hope someone can help me
Thanks
Marcel