question on finding account id from name
Thomas Baumgart
thb at net-bembel.de
Wed Jun 22 07:18:16 BST 2022
On Dienstag, 21. Juni 2022 22:46:35 CEST Jack via KMyMoney-devel wrote:
> I'm trying to find an way to easily switch between an investment
> account and it's brokerage account. I have figured out how to test for
> the two types of accounts (testing the .accountType() or looking for "
> (Brokerage)" at the end of the name.) However, I don't see any way to
> look up an account by name. Does this actually require looping through
> all accounts and testing if the name matches?
In master you can do this:
QString accountName;
auto account = MyMoneyFile::instance()->accountsModel()->itemByName(accountName);
or if you want to stick with the model type access to the data:
auto idx = MyMoneyFile::instance()->accountsModel()->indexByName(accountName);
auto name = idx.data(eMyMoney::Model::AccountNameRole).toString();
which in fact does the looping for you in AccountsModel::indexListByName().
Hope that helps.
--
Regards
Thomas Baumgart
https://www.signal.org/ Signal, the better WhatsApp
-------------------------------------------------------------
The only 'intuitive' interface is the nipple. After that, it's all learned.
-- Bruce Ediger, bediger at teal.csn.org, on X interfaces
-------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 868 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kmymoney-devel/attachments/20220622/7ccc64cb/attachment.sig>
More information about the KMyMoney-devel
mailing list