What is it exactly that you are trying to do? Since you are using Qt, why not use the facilities it provides? Or at least what std C++ provides (like strings instead of C strings).
What is it exactly that you are trying to do? Since you are using Qt, why not use the facilities it provides? Or at least what std C++ provides (like strings instead of C strings).
Hi, i change it for qStrings and it works in PC but when i compile in the mobile it crash:
Qt Code:
int comparator(const void *a, const void *b) { qDebug()<<"1"; qDebug()<<"2"; for (int i = 0; i < 6; ++i) { if (aaa.at(i).toAscii() != bbb.at(i).toAscii()) { // qDebug()<<"diference1:"<<aaa.at(i).toAscii() - bbb.at(i).toAscii(); return aaa.at(i).toAscii() - bbb.at(i).toAscii(); //return aa[i] - bb[i]; } } return 0; }To copy to clipboard, switch view to plain text mode
Executable file: 9064 2010-10-25T11:55:40 C:\NokiaQtSDK\Symbian\SDK\epoc32\release\gcce\udeb \meoKeyMap.exe
Package: 9332 2010-10-25T11:55:42 C:\Users\Ze\Documents\Qt\meoKeyMap\meoKeyMap.sis
Deploying application to 'Nokia E51 USB (COM6)'...
Copying installation file...
Installing application...
Starting application...
Application running with pid 1103.
[Qt Message] 1
Process 1103, thread 1104 stopped at 0x7b9e1644: A data abort exception has occurred.
Finished.
A lot of people ask me for a backtrace, do you know how can i get it using qt and the debugger?!
Why are you using bsearch() in the first place? If you have a sorted array, use qLowerBound(), qUpperBound() or qBinaryFind(). You don't need any custom comparators for that and certainly no C-ish code like this.
I have a sorted text file not an array. I have a QFile::map():
Qt Code:
To copy to clipboard, switch view to plain text mode
Can i do that with this?!
Yes, why not? Of course provided each item in the file is of the same size.
Qt Code:
qBinaryFind(container.begin(), container.end(), value);To copy to clipboard, switch view to plain text mode
But i can't do ptr.begin, can i give him the values? because i already know them!
i'm doing that way:
Qt Code:
QVector<int>::iterator i = qBinaryFind(bla.begin(),bla.end(),"111111");To copy to clipboard, switch view to plain text mode
it gives me some errors that i can't figure out:
..\binaryFind\mainwindow.cpp:26: error: invalid conversion from 'const char*' to 'char'
..\binaryFind\mainwindow.cpp:26: error: initializing argument 1 of 'QList<QByteArray> QByteArray::split(char) const'
..\binaryFind\mainwindow.cpp:27: error: cannot convert 'QList<QByteArray>::iterator' to 'int*' in initialization
Well, the code doesn't make any sense (syntactically) so I can't blame the compiler for refusing to build it.
And logically with the above code mapping the file to memory has no sense because you are copying anyway when calling split().
Can you help doing that job?! I know that i need more background from c/c++.... :s
Ok, here is a solution that copies the data. If you want to avoid a copy, modify it to suit your needs:
Qt Code:
To copy to clipboard, switch view to plain text mode
Thanks, i implement the binary seach by my self and use the QFile::seek to go the position i want in the file, and it work great! Thanks for all![]()
Bookmarks