2016-05-07 14 views
0

私は、入力ファイル(この場合はjpgファイル)を読むためにQCommandLineOptionを使用してコードを作成しています。私は正しくファイルパス&の名前をデータにアクセスするために追加する方法について私の頭をラップしようとしていますが、動作しません。コードは次のとおりです:QCommandLineOption入力ファイルを読む

#include <iostream> 
#include <QCoreApplication> 
#include <QCommandLineParser> 
#include <QCommandLineOption> 
#include <QString> 
#include <QImage> 
#include "imageconvert.h" 
#include "clanu_process.h" 

//--input=/Users/fakepath/coming-soon.jpg --  mask=/Users/fakepath/coming-soon_mask.jpg --output=/Users/fakepath/coming-soon_out_IFQ1.jpg 

int main(int argc, char *argv[]) 
{ 
    // ------------------------------------------ 
    //Command line parameters management 
    QCoreApplication app(argc, argv); 
    QCoreApplication::setApplicationName("clanu-inpainting"); 
    QCoreApplication::setApplicationVersion("1.0"); 

    QCommandLineParser parser; 
    parser.setApplicationDescription("Inpainting Console"); 
    parser.addHelpOption(); 
    parser.addVersionOption(); 

    QCommandLineOption inputFileOption(QStringList() << "i" << "input", "Fullpath and extension of the input <file>.", "file"); 
    parser.addOption(inputFileOption); 

    QCommandLineOption maskFileOption(QStringList() << "m" << "mask", "Fullpath and extension of the mask <file>.", "file"); 
    parser.addOption(maskFileOption); 

    QCommandLineOption outputFileOption(QStringList() << "o" << "output", "Fullpath and extension of the output <file>.", "file"); 
    parser.addOption(outputFileOption); 

    // Process the actual command line arguments given by the user 
    parser.process(app); 

    QString inputFileName = parser.value(inputFileOption); 
    QString maskFileName = parser.value(maskFileOption); 
    QString outputFileName = parser.value(outputFileOption); 

    std::cout << " input " << inputFileName.toStdString() << std::endl; 
    std::cout << " output " << outputFileName.toStdString() << std::endl; 
    std::cout << " mask " << maskFileName.toStdString() << std::endl; 

    if( maskFileName.isEmpty()) { std::cout << "!! Mask is NOT SET and must be set!" << std::endl; return -1; } 
    if( inputFileName.isEmpty()) { std::cout << "!! Input is NOT SET and must be set!" << std::endl; return -1; } 
    if(outputFileName.isEmpty()) { std::cout << "!! Output is NOT SET and must be set!" << std::endl; return -1; } 

    std::cout << " - Input image file read : " << inputFileName.toStdString() << std::endl; 
    std::cout << " - Mask image file read : " << maskFileName.toStdString() << std::endl; 
    std::cout << " - Output image file  : " << outputFileName.toStdString() << std::endl; 
    // ------------------------------------------ 
return 0; 
} 

私は「!!マスクは設定されていないため、設定する必要があります!コンパイル時には、文字列maskFileNameが空であることを意味します。何か案は ?

答えて

0

あなたのプログラムは正常に動作します。私はちょうどそれをコンパイルし、試して、それは動作します。

問題は、あなたがそれを与えたサンプル引数である:

--input=/Users/fakepath/coming-soon.jpg --  mask=/Users/fakepath/coming-soon_mask.jpg --output=/Users/fakepath/coming-soon_out_IFQ1.jpg 

あなたは-- maskにスペースを削除する必要があります。ファイルパスを扱うとき、それはあなたのパスにスペースを可能にするために、二重引用符でそれらをラップすることをお勧めします、サイドノートでは

--input=/Users/fakepath/coming-soon.jpg --mask=/Users/fakepath/coming-soon_mask.jpg --output=/Users/fakepath/coming-soon_out_IFQ1.jpg 

::だからにTIを変更

--input="/Users/fakepath/coming soon.jpg" --mask="/Users/fakepath/coming soon mask.jpg" --output="/Users/fakepath/coming soon out IFQ1.jpg" 
関連する問題