Bonjour à tous,
Je travaille actuellement sous QTCreator sur un code où je dois rentrer quelques paramètre en lignes de commandes (première étape avant de faire une IHM). Le code utilise la commande QCommandLineOption (puis QCommandLineParse) pour lire le chemin d'accès aux fichiers (ici des jpg). Mais je n'arrive pas à implémenter correctement ces chemins pour que le programme les récupère. Voici le code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#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;
}
J'obtiens ceci à la compilation (qui s'effectue correctement) : Nom : Capture d’écran 2016-05-08 à 08.40.24.png
Affichages : 165
Taille : 21,2 Ko
Ce qui signifie que le string correspondant au nom du "mask" est vide. J'ai essayé de plusieurs façons d'intégrer le chemin d'accès et le nom des 3 fichiers dans les commandes correspondantes mais rien n'y fait. Des idées ?