Code:
#include "mainwindow.h"
#include <QtCore>
#include <QtGui>
#include <stdio.h>
#include <string.h>
#include <QMessageBox>
int comparator(const void *a, const void *b);
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QString dir = QFileDialog::getOpenFileName(this, tr("Select Text File"),"",tr("Text (*.txt)"));
QFile f(dir);
int fileSize = f.size();
f.open(QIODevice::ReadOnly);
if(f.isOpen()){
uchar* ptr = f.map(0,fileSize,QFile::NoOptions);
char *ssid="60EFF9";
char *res =(char*) bsearch(ssid, ptr, 9704447, 17, comparator);
if (NULL == res) {
qDebug()<<"No match!!";
} else {
//qDebug()<<"Match!";
qDebug("Match found: %.10s\n", res+6);
}
}else{
qDebug()<<"loooool";
}
}
MainWindow::~MainWindow()
{
}
/*int comparator(const void *a, const void *b)
{
const char *aa = (const char *)a, *bb = (const char *)b;
for (int i = 0; i < 6; ++i) {
if (aa[i] != bb[i]) { //CRASH HERE <-----------------------------------------------------
return aa[i] - bb[i];
}
}
return 0;
}*/
int comparator(const void *a, const void *b)
{
qDebug()<<"1";
QString aaa(const_cast<char*>(reinterpret_cast<const char*>(a))); //CRASH HERE <-------------
QString bbb(const_cast<char*>(reinterpret_cast<const char*>(b)));
qDebug()<<"2";
for (int i = 0; i < 6; ++i) {
if (aaa.at(i).toAscii() != bbb.at(i).toAscii()) {
return aaa.at(i).toAscii() - bbb.at(i).toAscii();
}
}
return 0;
}
My aplication crash where i comment it, in PC works, in mobile crash!