×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    91

    Binary Search - Error

    Hi, i code an aplication that use the bsearch function from c, when i debug it to mobile it give me the following errors:

    Installing application...
    Starting application...
    Could not start application: General OS-related error
    Finished.
    My code is: http://pastebin.com/yrqG7axB

  2. #2
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Binary Search - Error

    Are your entries null-terminated? If yes, why don't you use strcmp as comparator, if not qDebug will crash.

  3. #3
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    91

    Re: Binary Search - Error

    I use the compartor because i need to compare the first 6 bytes of a total of 17 bytes. I tried to compile to desktop and it's works perfectly. The aplication in the mobile doesn't start so i can't even choose the file.

  4. #4
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Binary Search - Error

    Try this sample console application
    Code:
    #include <QtCore>
    
    int main(int argc, char **argv)
    {
        QFile file("myfile.txt");
        if(file.open(QIODevice::ReadOnly)) {
            int fileSize = file.size();
            int recordSize = 17;
            char ssid[] = "60EFF9";
    
            uchar* ptr = file.map(0, fileSize);
    
            char *res = (char*)bsearch(ssid, ptr, (fileSize / recordSize), recordSize,
                        (int(*)(const void*, const void*))strcmp);
    
            if (res)
                qDebug("Match found: %.10s\n", res+6);
            else
                qDebug() << "No match!!";
        } else {
            qDebug() << file.errorString();
        }   
    }

  5. #5
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    91

    Re: Binary Search - Error

    It run but the console close before i can read what it says.

  6. #6
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Binary Search - Error

    You should see at least "No such file or directory" debug message.

  7. #7
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    91

    Re: Binary Search - Error

    Quote Originally Posted by divanov View Post
    You should see at least "No such file or directory" debug message.
    i change "myfile.txt" to my file.

  8. #8
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    91

    Re: Binary Search - Error

    If i compile it to mobile it give the same error as my aplication!

  9. #9
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Binary Search - Error

    Do you have ReadUserData capability?

  10. #10
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    91

    Re: Binary Search - Error

    Quote Originally Posted by divanov View Post
    Do you have ReadUserData capability?
    No, but my problem was that Symbian doesn't like:

    int a;
    int b;
    int c=(a/b); ---> It make my aplication didn't start up! Error:"Not Supported function";

  11. #11
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    91

    Char - A data abort exception has occurred.

    Hi, when i call this funcion: char *res =(char*) bsearch(ssid, ptr, 9704447, 17, comparator); i use a comparator function and my aplication crash!

    comparator():
    Code:
    int comparator(const void *a, const void *b)
    {
        qDebug()<<"comparator()";
        const char *aa = (const char *)a, *bb = (const char *)b;
        qDebug()<<"1";
        for (int i = 0; i < 6; ++i) {
            qDebug()<<"2";
            qDebug()<<"i:"<<i;
            qDebug()<<"i:"<<i<<" aa:"<<aa[i]<<" bb:"<<bb[i];
            qDebug()<<"3";
            if (aa[i] != bb[i]) {
                return aa[i] - bb[i];
            }
        }
        return 0;
    }
    the debug:

    Executable file: 9058 2010-10-25T01:46:47 C:\NokiaQtSDK\Symbian\SDK\epoc32\release\gcce\udeb\meoKeyMap.exe
    Package: 9380 2010-10-25T01:46:50 C:\Users\Ze\Documents\Qt\meoKeyMap\meoKeyMap.sis
    Deploying application to 'Nokia E51 USB (COM4)'...
    Copying installation file...
    Installing application...
    Starting application...
    Application running with pid 875.

    [Qt Message] comparator()
    Process 875, thread 876 stopped at 0x7b95028c: A data abort exception has occurred.
    [Qt Message] 1
    [Qt Message] 2
    [Qt Message] i: 0
    Finished.

  12. #12
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Binary Search - Error

    Quote Originally Posted by metRo_ View Post
    No, but my problem was that Symbian doesn't like:

    int a;
    int b;
    int c=(a/b); ---> It make my aplication didn't start up! Error:"Not Supported function";
    The only problem here is that a and b are not initialized and b could possible be zero.
    If you change it to something like this, then no problem
    Code:
    int a = 10;
    int b = 20;
    int c = (a / b);
    GUI sample application
    Code:
    #include <QtGui>
    
    int main(int argc, char **argv)
    {
        QApplication app(argc, argv);
    
        QLabel label;
        QFile file("myfile.txt");
        if(file.open(QIODevice::ReadOnly)) {
            int fileSize = file.size();
            int recordSize = 17;
            char ssid[] = "60EFF9";
    
            uchar* ptr = file.map(0, fileSize);
    
            char *res = (char*)bsearch(ssid, ptr, (fileSize / recordSize), recordSize,
                        (int(*)(const void*, const void*))strcmp);
    
            if (res)
                label.setText(QString("Match found: %1").arg(res+6));
            else
                label.setText("No match!!");
        } else {
            label.setText(file.errorString());
        }
        label.show();
    
        return app.exec();
    }
    Last edited by divanov; 2010-10-25 at 08:43.

  13. #13
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    91

    Crash with Chars

    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!

  14. #14
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Crash with Chars

    Note, that QString constructor expects null-terminated string. Using constant 9704447 also looks suspicious. Also note that calling QIODevice::size () before you open the file returns bogus result.
    Last edited by divanov; 2010-10-25 at 12:32.

  15. #15
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    91

    Re: Crash with Chars

    Quote Originally Posted by divanov View Post
    Note, that QString constructor expects null-terminated string. Using constant 9704447 also looks suspicious. Also note that calling QIODevice::size () before you open the file returns bogus result.
    About the QFile:size() i alredy put it inside the openfile, thanks.

    the txt file have data like that: "00001E9800E8F588\n"

Page 1 of 2 12 LastLast

Similar Threads

  1. Search engine ERROR once again
    By stenlik in forum General Development Questions
    Replies: 5
    Last Post: 2008-09-16, 16:59
  2. SERVICE SEARCH ERROR on searchServices
    By mahmoudhadad in forum Bluetooth Technology
    Replies: 2
    Last Post: 2008-07-12, 00:29
  3. Bluetooth service search error
    By darwin_cyriac in forum Bluetooth Technology
    Replies: 2
    Last Post: 2008-07-10, 22:51
  4. Reading binary file with RReadFileStream error
    By maucem in forum Symbian C++
    Replies: 1
    Last Post: 2006-08-28, 16:07
  5. Error During Search for Bluetooth devices...
    By sblider in forum Symbian C++
    Replies: 1
    Last Post: 2004-02-22, 17:42

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •