当我使用QCommandLineOption
和QCommandLineParser
进行解析时,无法获得多个参数。
这就是我想要的:
dbmanager.exe -f args1 args2
我想获得args1
和args2
。但是我无法获得args2
。
我该怎么办?
答案 0 :(得分:0)
arg1和arg2看起来像位置参数,即应用程序期望以特定顺序给出的参数。
此代码段应帮助您获得所需的内容:
public void requestPayment(BigDecimal amount) {
// Disables the button to prevent multiple clicks.
//mGooglePayButton.setClickable(false);
// The price provided to the API should include taxes and shipping.
// This price is not displayed to the user.
String chargeAmount = amount.divide(MICROS).setScale(2, RoundingMode.HALF_EVEN).toString();
// String price = PaymentsUtil.microsToString(chargeAmount);
TransactionInfo transaction = PaymentsUtil.createTransaction(chargeAmount);
Parcel parcel = Parcel.obtain();
parcel.writeString(chargeAmount);
parcel.recycle();
transaction.writeToParcel(parcel, 0);
PaymentDataRequest request = PaymentsUtil.createPaymentDataRequest(transaction);
Task<PaymentData> futurePaymentData = mPaymentsClient.loadPaymentData(request);
// Since loadPaymentData may show the UI asking the user to select a payment method, we use
// AutoResolveHelper to wait for the user interacting with it. Once completed,
// onActivityResult will be called with the result.
AutoResolveHelper.resolveTask(futurePaymentData, Objects.requireNonNull(getActivity()), LOAD_PAYMENT_DATA_REQUEST_CODE);
}
然后检查以下参数和选项:
QCommandLineParser parser;
// define the parameters and options your application will use
parser.addPositionalArgument("arg1", QCoreApplication::translate("main", "this is the first argument."));
parser.addPositionalArgument("arg2", QCoreApplication::translate("main", "this is the second argument."));
// this is for the -f option
QCommandLineOption fOption(QStringList() << "f" << "foption",
QCoreApplication::translate("main", "does something optional."));
parser.addOption(fOption);
为使代码更健壮,您可能需要检查提供的位置参数的数量,并在缺少某些内容时发出错误/警告。