Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7792579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:13:43+00:00 2026-06-01T22:13:43+00:00

I am writing a class using Qt that needs to import a dictionary that

  • 0

I am writing a class using Qt that needs to import a dictionary that will be used to look up a command and build a command sentence. The commands are arranged in a hierarchical manner and have a corresponding hex key and value definition. For illustration purposes, it could look like this:

01 : Volume
        | - 01 : Step : 00=Down, 01=Up
        | - 02 : Set : ceil(255/100 * x)
02 : Power
        | - 01 : Power : 00=Off, 01=On
        | - 02 : Sleep : ...etc

I want to load this dictionary and then be able to search it for “Volume/Set/50” and return the command sentence “01 02 80” or look up “01 02 80” and return “Volume/Set/50.”

The actual implementation is a little more complex and has commands at different levels in the tree structure and could include any number and combination of commands from different levels in a single sentence.

Edit:

The comment provided by volodymyr below introduces a concept (Trie) that I was not familiar with. It may be the best implementation for this particular scenario, but I have to research it some more. I am still interested in an answer to my original question (with the addition of Trie):

What are the advantages and disadvantages of using each of these methods for this implementation?

  • Qt Tree Model
  • Nested Maps
  • Trie

Original question: (for context)

Would a Qt Tree Model, nested maps or some other means be better suited to store the dictionary? I realize “better” may be subjective, but I would like to know the trade offs.

I am already building a Qt Tree Model to display some other data in a QTreeView, so that code will already exist and could easily be used. Would the Tree Model allow more flexibility in loading dictionaries with different structures? Is there a better way to do this? or maybe a standard design pattern?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:13:45+00:00Added an answer on June 1, 2026 at 10:13 pm

    In my opinion, the number of items at each level in the command tree is too small to justify using a trie. A trie (see http://en.wikipedia.org/wiki/Trie), due to its large branching factor, is best for a large number of items — for example a natural-language dictionary, as volodymyr has pointed out.

    In fact, the number may be too small to justify even std::map. If there aren’t more than a couple dozen commands or codes at a given point in the tree, a linear search is probably about as fast as a search in a map, or faster. The memory representation as a vector or list would also be more compact. That said, std::map’s interface seems very well suited for what you’re trying to do, so, in practice, it’s probably still the best choice overall.

    I can’t see how QTreeModel can be better than std::map from any point of view (speed, memory, ease of use), except that it may mesh better with the rest of your code, since it’s Qt-based. However, if you even vaguely suspect that this part may have a use without Qt, I would not hesitate to choose the standard library stuff (std::map). The only truly compelling reason to choose QTreeModel over std::map would be if you actually used it in a QTreeView.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a class in C++ that I cannot debug by using F5. The
As I know, GWT needs that code that will be used on client side
I am writing a Graph-class using boost-graph-library. I use custom vertex and edge properties
I was writing a database handler class in PHP using the mysqli class and
I am writing a web server application in C# and using StreamReader class to
I`m writing client-server app for windows using WinSock and I have class for server.
I am writing some code to type strings using the Robot class. Everything is
I am writing unit for a class which looks like following using nunit and
I'm writing a screen capture module using the Robot class. I'm taking screenshots of
I am writing a small Android game using a SurfaceView class. The outline of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.