Results 1 to 4 of 4

Thread: necessitas: android intent & QProcess issues

  1. #1
    Join Date
    Oct 2006
    Location
    Hawaii
    Posts
    130
    Thanks
    48
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default necessitas: android intent & QProcess issues

    Currently I am working on a simple application which is meant to spawn the ZXING barcode scanner.

    Using QProcess, I am able to make a slot which launches the scanner application and then returns to my application when a scan has completed.

    A few problems have occurred which I can not figure out:

    1) When launchScanner() is called, the "item scanned!", and "scanner output" messages appear instantly and the stacked widget changes index even though the scanner application is not finished. The scanner window is still open while my app continues under it. This means that my slot is not waiting for the scanner to finish before moving on. I am not sure if this is an issue with QProcess on the android or something I missed in my code.

    2) readAll() returns "Starting: Intent { act=com.google.zxing.client.android.SCAN (has extras) }" rather than any return value (barcode contents) from the scanner finishing it's scan. This could be caused by QProcess not waiting thereby leaving readall() to only report the results right after it started rather than everything.

    Is there a better way to use an intent than launching it with QProcess? Also, how can I get the return information once I call it?


    Qt Code:
    1. void MainWindow::launchScanner() {
    2.  
    3. QProcess barcode;
    4. barcode.setProcessChannelMode(QProcess::MergedChannels);
    5.  
    6. barcode.start("am start -a com.google.zxing.client.android.SCAN -e SCAN_FORMATS \"QR_CODE\"");
    7.  
    8. if (!barcode.waitForStarted()) {
    9. qDebug() << "********************** Scanner start failed! " << barcode.errorString();
    10. } else {
    11. qDebug() << "********************** Scanner started!";
    12. }
    13.  
    14.  
    15. if (!barcode.waitForFinished(-1)) {
    16. qDebug() << "********************** Scanner unable to finish! " << barcode.errorString();
    17. } else {
    18. qDebug() << "********************** Scanner output: " << barcode.readAll();
    19. }
    20.  
    21. //do something here once we figure out how to get value back from the scanner
    22.  
    23. qDebug() << "********************** Item scanned! ******************************";
    24.  
    25.  
    26. //change the stack widget to show a different interface
    27. ui.mainStack->setCurrentIndex(1);
    28. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    May 2011
    Posts
    239
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: necessitas: android intent & QProcess issues

    About making QProcess wait for the process to complete, see an old illustrative discussion http://lists.trolltech.com/qt-intere...ad01232-0.html

  3. #3
    Join Date
    Oct 2006
    Location
    Hawaii
    Posts
    130
    Thanks
    48
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: necessitas: android intent & QProcess issues

    I modified my code to work using signals/slots to go to the next step and the result was the same: the process instantly starts, finishes, and updates the interface behind the running scanner, which did not finish until I scanned a barcode.

    I think what could be happening is that QProcess is launching the "am" command, which in turn launches the program. After the program launches, the "am" command exits and so QProcess signals that and is not actually attached to the barcode scanner at all.

    This may or may not be a problem as long as I can figure out how I can get at the result intent. Any ideas?

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) {
    2.  
    3. ui.setupUi(this);
    4.  
    5. barcode = new QProcess();
    6.  
    7. connect(barcode, SIGNAL(readyReadStandardOutput()), this, SLOT(readScannerOutput()));
    8. connect(barcode, SIGNAL(started()), this, SLOT(scannerStarted()));
    9. connect(barcode, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(scannerFinished(int, QProcess::ExitStatus)));
    10.  
    11.  
    12. connect( ui.checkinButton, SIGNAL( clicked() ), this, SLOT( launchScanner() ) );
    13.  
    14.  
    15.  
    16. }
    17.  
    18. MainWindow::~MainWindow() {
    19.  
    20. }
    21.  
    22. //slot to launch the scanner and do something with the result:
    23. void MainWindow::launchScanner() {
    24.  
    25.  
    26. //if the scanner is not already running launch the scanner:
    27. if (barcode->state() == QProcess::Running) {
    28.  
    29. qDebug() << "********************** Scanner was already running! Do not start again!";
    30.  
    31. } else {
    32.  
    33. barcode->setProcessChannelMode(QProcess::MergedChannels);
    34. barcode->setReadChannel(QProcess::StandardOutput);
    35. barcode->start("am start -a com.google.zxing.client.android.SCAN -e SCAN_FORMATS \"QR_CODE\"");
    36. qDebug() << "********************** Starting scanner...";
    37.  
    38. }
    39.  
    40.  
    41. }
    42.  
    43. void MainWindow::scannerStarted() {
    44.  
    45. qDebug() << "********************** Scanner started!";
    46.  
    47. }
    48.  
    49. void MainWindow::scannerFinished(int exitCode, QProcess::ExitStatus exitStatus) {
    50.  
    51. if (exitStatus == QProcess::CrashExit) {
    52. qDebug() << "********************** Barcode scanner crashed!" << barcode->errorString();
    53. } else {
    54. qDebug() << "********************** Barcode scanner finished!" << barcode->readAll();
    55. ui.mainStack->setCurrentIndex(1);
    56. qDebug() << "********************** Interface changed to the next step.";
    57. }
    58.  
    59. }
    60.  
    61.  
    62. void MainWindow::readScannerOutput() {
    63.  
    64. QTextStream s(barcode);
    65. QString str = s.readAll();
    66. qDebug() << "********************** The scanner speaks: " << str;
    67.  
    68. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jun 2015
    Posts
    1
    Qt products
    Qt5
    Platforms
    MacOS X Android

    Default Re: necessitas: android intent & QProcess issues

    hi buddy, I have the same problem. Do you know how to read the result intent? Please reply as you solved this problem.

Similar Threads

  1. Android / necessitas: SQLITE error ("Driver not loaded")
    By Al_ in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 28th August 2011, 15:06
  2. Necessitas Qt for Android issue
    By rickrvo in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 8th June 2011, 10:30
  3. Qt for Android. Necessitas
    By freely in forum Newbie
    Replies: 3
    Last Post: 27th May 2011, 18:12
  4. QProcess issues
    By oguzy in forum Qt Programming
    Replies: 1
    Last Post: 13th September 2008, 14:15
  5. issues with kprocess and qprocess
    By soul_rebel in forum Qt Programming
    Replies: 1
    Last Post: 7th April 2006, 19:39

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.