diff --git a/CellFrameDashboardService/DapChainWalletHandler.cpp b/CellFrameDashboardService/DapChainWalletHandler.cpp index 4da008ac980a5c0b0b36a7d7f7c5ae45b89b76c1..8d6c250e73ab80a248fa92dde3e5d34531d175b3 100755 --- a/CellFrameDashboardService/DapChainWalletHandler.cpp +++ b/CellFrameDashboardService/DapChainWalletHandler.cpp @@ -1,5 +1,6 @@ #include "DapChainWalletHandler.h" #include <QDebug> +#include <QRegularExpression> DapChainWalletHandler::DapChainWalletHandler(QObject *parent) : QObject(parent) { @@ -42,27 +43,36 @@ QMap<QString, QVariant> DapChainWalletHandler::getWallets() QProcess process; process.start(QString("%1 wallet list").arg(CLI_PATH)); process.waitForFinished(-1); - QString str = QString::fromLatin1(process.readAll()); - QRegExp rx(":{1,1}([\\s\\w\\W]+)(\\n|\\r){1,1}" ); - rx.setMinimal(true); - int pos = 0; - int x {0}; - QString tempName; - while ((pos = rx.indexIn(str, pos)) != -1) - { - if(x == 0) - { - tempName = rx.cap(1); - ++x; - } - else - { - map.insert(tempName, rx.cap(1)); - x = 0; - } - pos += rx.matchedLength(); + QByteArray result = process.readAll(); + QRegularExpression rx("wallet:\\s(.+)\\s+addr:\\s(.+)", QRegularExpression::MultilineOption); + QRegularExpressionMatchIterator itr = rx.globalMatch(result); + while (itr.hasNext()) { + QRegularExpressionMatch match = itr.next(); + map[match.captured(1)] = match.captured(2); } + +// QString str = QString::fromLatin1(process.readAll()); +// QRegExp rx(":{1,1}([\\s\\w\\W]+)(\\n|\\r){1,1}" ); +// rx.setMinimal(true); +// int pos = 0; +// int x {0}; +// QString tempName; +// while ((pos = rx.indexIn(str, pos)) != -1) +// { +// if(x == 0) +// { +// tempName = rx.cap(1); +// ++x; +// } +// else +// { +// map.insert(tempName, rx.cap(1)); +// x = 0; +// } +// pos += rx.matchedLength(); +// } + return map; }