×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    6

    Can't Get Started with Sensors

    I'm new to developing for mobile devices. I just made a simple game to get started and now I'm ready to advance to sensors. However, I can't seem to get going here. I've read API documentation and various posts, but I can't seem to get anything to compile. Can someone sugest a barebones starting point for me to just get a read on the ambient light sensor?

  2. #2
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Can't Get Started with Sensors

    What errors are you getting?

    Did you put the QTM_USE_NAMESPACE macro in your source?

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    6

    Re: Can't Get Started with Sensors

    Yeah, I finally got the original errors going, now I just have segmentation faults. I have a QAmbientLightSensor object and I use connectToBackend(). Then i have a pushbutton that when clicked gets the reader object and reads it....

    Here's my code:

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QAmbientLightReading>
    #include "string.h"

    QTM_USE_NAMESPACE //(2)


    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    //aLS.start();
    aLS.connectToBackend();
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow:n_pushButton_clicked()
    {

    QString str;
    str.setNum(aLS.reading()->lightLevel());
    this->ui->label->setText(str);

    }

  4. #4
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Can't Get Started with Sensors

    So, when/where do the segmentation faults occur? You are running with the debugger, right?

    (And it would be easier to help you if you showed us your implementation of the aLS object.)

    [OK, I see -- connectToBackend is an undocumented function. Not clear whether that's intentional or a bug in the documentation markup.]
    Last edited by danhicksbyron; 2010-11-22 at 02:42.

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    6

    Re: Can't Get Started with Sensors

    Sorry, aLS is just defined as QAmbientLightSensor aLS in the header file. It's quite possible I'm not supposed to connectToBackend, I'm just really unclear of how to get the sensor data.

    I am running with the debugger. Without the debugger, it just crashes with a windows error message. I get the segmentation fault when I click my button (IE the on_pushbutton_clicked() function runs. I know it happens when I do aLS.reading() as I did a step through of a similar version of this code.

  6. #6
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Can't Get Started with Sensors

    Where is it crashing? Right in the beginning of the QAmbi... code, or somewhere deep inside. If right at the start it would suggest that your QAmbi... object isn't set up right or has gotten clobbered. If it's crasing in lightLevel() then it may be that reading() returned a null (or otherwise invalid) pointer.

  7. #7
    Registered User
    Join Date
    May 2010
    Posts
    6

    Re: Can't Get Started with Sensors

    I think reading() is returning a null pointer. But I don't know why. Have you used any of the Sensor objects? I'm sure I'm just not using it right....it also looks like it's not active yet based on the breakpoint snapshot of that object....Any thoughts?

  8. #8
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Can't Get Started with Sensors

    Never used any of it.

    You might try testing connectedToBackend() to see if it's "live" before trying to read. And when debugging it's sometimes wise to test pointers before using them.

  9. #9
    Registered User
    Join Date
    May 2010
    Posts
    6

    Re: Can't Get Started with Sensors

    Again, I'm just trying to get the sensor API working. Normally I would do such checks, but I'm sure I haen't even set it up right. I'm hoping someone who is familiar with that can lead me in the right direction.

  10. #10
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Can't Get Started with Sensors

    Quote Originally Posted by nessies2003 View Post
    but I'm sure I haen't even set it up right.
    Right, so take baby steps. Try to isolate the problem somehow.

Similar Threads

  1. N96+sensors (another one...)
    By aesteves in forum Mobile Java General
    Replies: 0
    Last Post: 2009-11-04, 17:18
  2. JavaME and Sensors
    By gpaes in forum Mobile Java General
    Replies: 15
    Last Post: 2009-06-23, 16:20
  3. Sensors
    By kamaljaiswal in forum Symbian User Interface
    Replies: 17
    Last Post: 2008-11-21, 09:41
  4. n96 + sensors
    By psinno in forum Symbian
    Replies: 3
    Last Post: 2008-11-10, 00:46
  5. sensors on mobile
    By delhiris in forum Mobile Java General
    Replies: 1
    Last Post: 2007-07-20, 16:45

Posting Permissions

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