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?
void MainWindow::launchScanner() {
barcode.
setProcessChannelMode(QProcess::MergedChannels);
barcode.start("am start -a com.google.zxing.client.android.SCAN -e SCAN_FORMATS \"QR_CODE\"");
if (!barcode.waitForStarted()) {
qDebug() << "********************** Scanner start failed! " << barcode.errorString();
} else {
qDebug() << "********************** Scanner started!";
}
if (!barcode.waitForFinished(-1)) {
qDebug() << "********************** Scanner unable to finish! " << barcode.errorString();
} else {
qDebug() << "********************** Scanner output: " << barcode.readAll();
}
//do something here once we figure out how to get value back from the scanner
qDebug() << "********************** Item scanned! ******************************";
//change the stack widget to show a different interface
ui.mainStack->setCurrentIndex(1);
}
void MainWindow::launchScanner() {
QProcess barcode;
barcode.setProcessChannelMode(QProcess::MergedChannels);
barcode.start("am start -a com.google.zxing.client.android.SCAN -e SCAN_FORMATS \"QR_CODE\"");
if (!barcode.waitForStarted()) {
qDebug() << "********************** Scanner start failed! " << barcode.errorString();
} else {
qDebug() << "********************** Scanner started!";
}
if (!barcode.waitForFinished(-1)) {
qDebug() << "********************** Scanner unable to finish! " << barcode.errorString();
} else {
qDebug() << "********************** Scanner output: " << barcode.readAll();
}
//do something here once we figure out how to get value back from the scanner
qDebug() << "********************** Item scanned! ******************************";
//change the stack widget to show a different interface
ui.mainStack->setCurrentIndex(1);
}
To copy to clipboard, switch view to plain text mode
Bookmarks