QProcess and scanimage (Linux)



  • I'm trying to make the QProcess class work with the linux scanimage application to scan documents that are on paper.

    My scanner is a Canon CanoScan.

    I have tried several ways, but the QProcess START statement does that it works, but it does not trigger the scanner.

    Anyone have any tips?

    void ClasseScanner :: on_pbScanDOC_clicked () {
       QString tipo_os = QSysInfo :: productType ();

    QString file_folder = QStandardPaths :: writableLocation (QStandardPaths :: AppConfigLocation);
       folder_file.append ("/ docto_scan.tif");

    QString command = "scanimage -l 0 -t 0 -x 90 -and 220 -mode Color --resolution 150 --rightness 0 --contrast 0 --format = tiff>";
       command.append (file_file);

    if (type_us.pare ("ubuntu") == 0) {
         process = new QProcess (this);
         process-> start (command);

    if (! process-> waitForFinished (-1)) qDebug () << "Failed:" << process-> errorString ();
         else qDebug () << "OK" << process-> readAll ();
       }
    }


  • Lifetime Qt Champion

    Hi,

    Please build the argument list like shown in the QProcess documentation.



  • @cvitagliano said in QProcess and scanimage (Linux):

    QString command = "scanimage -l 0 -t 0 -x 90 -and 220 -mode Color --resolution 150 --rightness 0 --contrast 0 --format = tiff>";    command.append (file_file);

    If I read you right, your command is using the > output redirection symbol right at the end, to send output to a file? You won't be able to do that if you execute a QProcess with scanimage as the executable.

    You will need either to send the whole string for execution to /bin/sh or /bin/bash so that the shell interprets and acts on the > for you, or you could use http://doc.qt.io/qt-5/qprocess.html#setStandardOutputFile to set up the output file yourself from the calling program instead.



  • @JonB Thank you very much. The two alternatives worked perfectly.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.