QCommandLineOption读取输入文件
QCommandLineOption reading input files
我正在编写一个使用QCommandLineOption读取输入文件(在本例中为jpg文件)的代码。我正试着思考如何正确地添加filepath&名称以访问数据,但它不起作用。这是代码:
#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;
}
编译时我得到"!!Mask未设置,必须设置!",这意味着字符串maskFileName为空。有什么想法吗?
您的程序运行良好。我只是编译了它并尝试过,它很有效。
问题出在你给出的示例参数上:
--input=/Users/fakepath/coming-soon.jpg -- mask=/Users/fakepath/coming-soon_mask.jpg --output=/Users/fakepath/coming-soon_out_IFQ1.jpg
您需要删除-- mask
中的空格。因此,将ti更改为:
--input=/Users/fakepath/coming-soon.jpg --mask=/Users/fakepath/coming-soon_mask.jpg --output=/Users/fakepath/coming-soon_out_IFQ1.jpg
顺便说一句,在处理文件路径时,最好用双引号将它们括起来,以便在路径中留出空格:
--input="/Users/fakepath/coming soon.jpg" --mask="/Users/fakepath/coming soon mask.jpg" --output="/Users/fakepath/coming soon out IFQ1.jpg"
相关文章:
- C++文本文件输入
- C++ 中文件输入输出中的长长 v/s int
- 如何修复函数中的 fstream 文件输入以将正确的信息存储在结构数组中?
- 用空格填充 2D 数组(从文件输入)
- 流对象来表示文件输入,然后是标准输入?
- 用精神解析文件输入
- 从文件输入和输出
- 来自文本文件输入 c++ 的向量
- 如何通过键盘或分数文件输入分数
- 了解文件输入和输出,我可以写入文件,但无法从文件打印
- 词频程序 - 文件输入太大?
- 尝试从 csv 文件输入大量数据时出错
- 如何将文件从文件输入到C 中的矩阵中
- 如何从Windows CMD运行可执行文件并将其传递给文件输入的参数参数和重定向
- 如何解析文本文件并使用构造函数中的文件输入来创建对象的容器
- 这是读取文件输入的正确方法吗?
- 如何在 c++ 中使用二进制文件输入/输出读取/写入结构的字符串类型成员
- 如何创建一个具有空值、递减编号系统和.txt文件输入值的二维阵列网格
- C 文件输入流循环问题
- 使用对输入整数的文件输入