Results 1 to 6 of 6

Thread: QT to Android serial port API problem?

  1. #1
    Join Date
    Dec 2011
    Posts
    6
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QT to Android serial port API problem?

    Hello,

    Has anyone succeeded to run android serial port with QT using Nessesitas?
    At the moment I am trying to learn JNI to reach serial ports here is some example of API:

    http://code.google.com/p/android-ser...rialPort.c?r=4

    At the moment unsuccessful.. So may be there is some one who made it work and have some example?

  2. #2
    Join Date
    Dec 2011
    Posts
    6
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QT to Android serial port API problem?

    I faced another problem in way of solving Serial port problem in Android:

    In emulator application always crashes at:

    JavaVM *m_javaVM;
    jint ret;
    JNIEnv *env;
    ret = m_javaVM->GetEnv((void **) &env, JNI_VERSION_1_6);

    Has anyone ever tried to use QT for Android???

  3. #3
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QT to Android serial port API problem?

    Hi,

    Which version of Nessesitas are you using. Please take a look at this thread http://www.qtcentre.org/threads/4169...he-GPS-Service

    I that example, I extern the javaVM pointer from qtmain_android.cpp (always included in your application ) to use it with the JNI. I think this is not needed in the new newest versions of neccesitas where you can use the android interface.

    Good luck.
    Carlos.
    Last edited by qlands; 23rd December 2011 at 22:09.

  4. #4
    Join Date
    Dec 2011
    Posts
    6
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QT to Android serial port API problem?

    Thank you for replay!
    I am using latest version of necessitas: necessitas-0.3
    Moreover I am trying to replicate gps project by running my own application and seems unsuccessful.

    I have two files SerialPort.c and its H file:
    http://code.google.com/p/android-ser...rialPort.c?r=4
    http://code.google.com/p/android-ser...pec=svn40&r=40

    I simple create necessitas new project with these two files and able to compile only by changing path to jni.h :
    #include </home/darka/Archyvas/android-ndk-r7/platforms/android-14/arch-arm/usr/include/jni.h>
    Originally there are two include paths in SerialPort.c and SerialPort.h: #include <jni.h>
    wich points to:
    /usr/lb/jvm/java-1.6.0-openjdk/include/jni.h

    In this case errors appears:
    ../SerialPort.c:-1: error: undefined reference to `__android_log_print'
    ..
    SerialPort.c:-1: error: undefined reference to `__android_log_print'

    So it seems that problem is in jni.h file, thus I change it to:

    #include </home/darka/Archyvas/android-ndk-r7/platforms/android-14/arch-arm/usr/include/jni.h>

    in SerialPort.c and SerialPort.h files.

    Then using Target: Android in QT project settings I am able to build it and even run to emulator until initialization of ret = m_javaVM->GetEnv((void **) &env, JNI_VERSION_1_6);
    I have associated code with button slot:
    JavaVM *m_javaVM;
    jint ret;
    JNIEnv *env;
    ret = m_javaVM->GetEnv((void **) &env, JNI_VERSION_1_6);

    So when I press button segmentation fault appears.

    Moreover in GPS example file qtmain_android.cpp is:
    JNIEnv* env;
    if (m_javaVM->AttachCurrentThread((void**)&env, NULL)<0)
    {
    qCritical()<<"AttachCurrentThread failed";
    return false;
    }


    So I am trying to do similar thing by using: AttachCurrentThread.

    using: ret = vm->AttachCurrentThread( (void**)&env, NULL);
    Error appears:

    ../serial_android-build--Necessitas_Qt_4_8_0_for_Android_armv5_Release/../serial_android/mainwindow.cpp:87: error: invalid conversion from 'void**' to 'JNIEnv**'
    ../serial_android/mainwindow.cpp:87: error: initializing argument 1 of 'jint _JavaVM::AttachCurrentThread(JNIEnv**, void*)'


    When I remove (void**) : ret = vm->AttachCurrentThread( &env, NULL);

    Application runs but crashes

    Any help? It seems that wrong jni.h files I include to project..

  5. #5
    Join Date
    Dec 2011
    Posts
    6
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QT to Android serial port API problem?

    It seems that is almost no help here in this forum

    Moreover, I have some progress. I tried to make simple program using example: http://jgoday.wordpress.com/2009/04/...with-qt-part1/
    to make sure that program is able to run using JNI.

    At the moment I am able to compile project and Get simple program run on Desktop by returning JAVA version (see attachment): test_JNI.tar.gz

    But when compiling for Android error appears:
    /home/darka/ProgramFiles/QT_work/Android/JNI_1/test_JNI-build--Necessitas_Qt_4_8_0_for_Android_armv7a_Release/../../../../necessitas/Android/Qt/480/armeabi-v7a/src/android/cpp/qtmain_android.cpp:62: error: invalid conversion from 'JNIEnv**' to 'void**'

    An error points to file qtmain_android.cpp:62:

    JNIEnv* env;
    points here-> if (m_javaVM->AttachCurrentThread(&env, NULL)<0)
    {
    qCritical()<<"AttachCurrentThread failed";
    return false;
    }


    So.. any help?? What am I doing wrong??

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QT to Android serial port API problem?

    It seems that is almost no help here in this forum
    Probably because you are asking questions about accessing specific interfaces from a third-party Qt extension that few here (apparently) have been using. Have you tried asking in the forum and wiki dedicated to Necessitas?

Similar Threads

  1. qext-serial-port write problem.
    By rex in forum Qt Programming
    Replies: 11
    Last Post: 9th December 2013, 08:18
  2. Serial Port Reading problem
    By sfabel in forum Qt Programming
    Replies: 12
    Last Post: 18th February 2010, 15:59
  3. serial port issues
    By jhowland in forum Qt Programming
    Replies: 7
    Last Post: 12th January 2009, 14:38
  4. serial port communiction
    By jagadish in forum Qt Programming
    Replies: 4
    Last Post: 7th July 2007, 13:04
  5. Serial Port
    By b1 in forum Qt Programming
    Replies: 2
    Last Post: 18th January 2007, 03:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.