MainWindow
::MainWindow(QWidget *parent
) {
ui.setupUi(this);
connect(barcode, SIGNAL(readyReadStandardOutput()), this, SLOT(readScannerOutput()));
connect(barcode, SIGNAL(started()), this, SLOT(scannerStarted()));
connect(barcode,
SIGNAL(finished
(int,
QProcess::ExitStatus)),
this,
SLOT(scannerFinished
(int,
QProcess::ExitStatus)));
connect( ui.checkinButton, SIGNAL( clicked() ), this, SLOT( launchScanner() ) );
}
MainWindow::~MainWindow() {
}
//slot to launch the scanner and do something with the result:
void MainWindow::launchScanner() {
//if the scanner is not already running launch the scanner:
if (barcode
->state
() == QProcess::Running) {
qDebug() << "********************** Scanner was already running! Do not start again!";
} else {
barcode
->setProcessChannelMode
(QProcess::MergedChannels);
barcode
->setReadChannel
(QProcess::StandardOutput);
barcode->start("am start -a com.google.zxing.client.android.SCAN -e SCAN_FORMATS \"QR_CODE\"");
qDebug() << "********************** Starting scanner...";
}
}
void MainWindow::scannerStarted() {
qDebug() << "********************** Scanner started!";
}
void MainWindow
::scannerFinished(int exitCode,
QProcess::ExitStatus exitStatus
) {
if (exitStatus
== QProcess::CrashExit) { qDebug() << "********************** Barcode scanner crashed!" << barcode->errorString();
} else {
qDebug() << "********************** Barcode scanner finished!" << barcode->readAll();
ui.mainStack->setCurrentIndex(1);
qDebug() << "********************** Interface changed to the next step.";
}
}
void MainWindow::readScannerOutput() {
qDebug() << "********************** The scanner speaks: " << str;
}
MainWindow::MainWindow(QWidget *parent) {
ui.setupUi(this);
barcode = new QProcess();
connect(barcode, SIGNAL(readyReadStandardOutput()), this, SLOT(readScannerOutput()));
connect(barcode, SIGNAL(started()), this, SLOT(scannerStarted()));
connect(barcode, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(scannerFinished(int, QProcess::ExitStatus)));
connect( ui.checkinButton, SIGNAL( clicked() ), this, SLOT( launchScanner() ) );
}
MainWindow::~MainWindow() {
}
//slot to launch the scanner and do something with the result:
void MainWindow::launchScanner() {
//if the scanner is not already running launch the scanner:
if (barcode->state() == QProcess::Running) {
qDebug() << "********************** Scanner was already running! Do not start again!";
} else {
barcode->setProcessChannelMode(QProcess::MergedChannels);
barcode->setReadChannel(QProcess::StandardOutput);
barcode->start("am start -a com.google.zxing.client.android.SCAN -e SCAN_FORMATS \"QR_CODE\"");
qDebug() << "********************** Starting scanner...";
}
}
void MainWindow::scannerStarted() {
qDebug() << "********************** Scanner started!";
}
void MainWindow::scannerFinished(int exitCode, QProcess::ExitStatus exitStatus) {
if (exitStatus == QProcess::CrashExit) {
qDebug() << "********************** Barcode scanner crashed!" << barcode->errorString();
} else {
qDebug() << "********************** Barcode scanner finished!" << barcode->readAll();
ui.mainStack->setCurrentIndex(1);
qDebug() << "********************** Interface changed to the next step.";
}
}
void MainWindow::readScannerOutput() {
QTextStream s(barcode);
QString str = s.readAll();
qDebug() << "********************** The scanner speaks: " << str;
}
To copy to clipboard, switch view to plain text mode
Bookmarks