Program Crash HOW TO get user input and convert to hexadecimal
Hi Dear All, I am writing a program which will read the user's input from lineEdit and convert it to Hexadecimal, but seems the program will crash, and my Fedora 11 starts to collect bugs.
void MainWindow::on_changeMACButton_clicked()
{
QLineEdit *lineEdit = new QLineEdit(this);
QString hex[6]=NULL;
for(int i=0;i<6;i++){
hex]=lineEdit->text();}
}
After i build(sucessful) and run it, the whole program will crash and Fedora will start collecting bugs. Think quite some time but still can not get any clue.......please help
Re: Program Crash HOW TO get user input and convert to hexadecimal
What kind of input do you expect? Do you wish to convert each character to it's number representation or do you wish to read a number and display that in hexadecimal format?
I'm pretty sure your code doesn't do what you want it to.
This is an array of 6 QStrings. You can't initialize it to NULL.
Re: Program Crash HOW TO get user input and convert to hexadecimal
the QLineEdit should not be a local variable -- it should be on the form. Suggest you use something like this to get the hex value:
Code:
bool ok;
int num = lineEdit.text().toInt(&ok);
Re: Program Crash HOW TO get user input and convert to hexadecimal
Thanks guys, I already solved the problem. your suggestions gave alot hint to me....
I just did like this
QString hex[6];
const char *set;
int hexnum[6];
/ for loop/
hex[i]=ui->lineEdit-text();
/for loop/
hexnum[i]=(char) (strtoul (hex[i].toAscii().data(),0,16) &0xFF);
Thanks
Re: Program Crash HOW TO get user input and convert to hexadecimal
Quote:
Originally Posted by
hbtdtg
/for loop/
hexnum[i]=(char) (strtoul (hex[i].toAscii().data(),0,16) &0xFF);
Hi, instead of this construction, you could use QString::toInt to convert your string to a hex number.
Ginsengelf