Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Storing enum in a list?
QtWS25 Last Chance

Storing enum in a list?

Scheduled Pinned Locked Moved Solved General and Desktop
enumfind
7 Posts 2 Posters 855 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lansing
    wrote on last edited by
    #1

    I'm making a simple find and replace function for my text editor. And there are a few checkbox for the flnd flags like "match case" and "whole words". When the find button is clicked, the checkbox selections will be stored in a QMap<QString, bool> and send along with the search text to the find function.

    In the find function I will unpack the findFlags QMap and check their state to add flags like QTextDocument::FindCaseSensitively to the find function. I want to store these enum in something like a QStringList that at the end I can paste them in the find function in one go like this.

    editor->find(a_text, findFlagsList.join(" | "))
    
    // I want it to print out like this
    editor->find(a_text, QTextDocument::FindCaseSensitively | QTextDocument::FindWholeWords)
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      But why a string list ?
      You can just store them as QFlags<FindFlag>
      And give that directly to editor->find
      You can no do that with strings.

      L 1 Reply Last reply
      1
      • mrjjM mrjj

        Hi
        But why a string list ?
        You can just store them as QFlags<FindFlag>
        And give that directly to editor->find
        You can no do that with strings.

        L Offline
        L Offline
        lansing
        wrote on last edited by lansing
        #3

        @mrjj

        Hi I tried QFlags<FindFlag> findFlags but I got the error unknown type name 'FindFlag'

        mrjjM 1 Reply Last reply
        0
        • L lansing

          @mrjj

          Hi I tried QFlags<FindFlag> findFlags but I got the error unknown type name 'FindFlag'

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi
          Its

          QFlags<QTextDocument::FindFlag> findFlags;
          
          L 1 Reply Last reply
          2
          • mrjjM mrjj

            Hi
            Its

            QFlags<QTextDocument::FindFlag> findFlags;
            
            L Offline
            L Offline
            lansing
            wrote on last edited by
            #5

            @mrjj

            Hi how do I add QTextDocument::FindFlag enum to this variable? It only allows me to assign the flags in one time.

            findFlags = QTextDocument::FindCaseSensitively | QTextDocument::FindWholeWords;

            I want to do it like

            if (matchCaseChecked) {
                findFlags += QTextDocument::FindCaseSensitively;
            }
            
            if (wholeWordsChecked) {
                findFlags += QTextDocument::FindWholeWords;
            }
            
            mrjjM 1 Reply Last reply
            0
            • L lansing

              @mrjj

              Hi how do I add QTextDocument::FindFlag enum to this variable? It only allows me to assign the flags in one time.

              findFlags = QTextDocument::FindCaseSensitively | QTextDocument::FindWholeWords;

              I want to do it like

              if (matchCaseChecked) {
                  findFlags += QTextDocument::FindCaseSensitively;
              }
              
              if (wholeWordsChecked) {
                  findFlags += QTextDocument::FindWholeWords;
              }
              
              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @lansing
              Hi
              You can still just OR them together
              if (matchCaseChecked) {
              findFlags |= QTextDocument::FindCaseSensitively;
              }

              L 1 Reply Last reply
              1
              • mrjjM mrjj

                @lansing
                Hi
                You can still just OR them together
                if (matchCaseChecked) {
                findFlags |= QTextDocument::FindCaseSensitively;
                }

                L Offline
                L Offline
                lansing
                wrote on last edited by
                #7

                @mrjj

                This is what I'm looking for, thank you.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved