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 1 Aug 2020, 22:47 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
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 1 Aug 2020, 23:22 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 Aug 2020, 23:43
      1
      • M mrjj
        1 Aug 2020, 23:22

        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 1 Aug 2020, 23:43 last edited by lansing 8 Jan 2020, 23:43
        #3

        @mrjj

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

        M 1 Reply Last reply 2 Aug 2020, 08:00
        0
        • L lansing
          1 Aug 2020, 23:43

          @mrjj

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

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 2 Aug 2020, 08:00 last edited by
          #4

          Hi
          Its

          QFlags<QTextDocument::FindFlag> findFlags;
          
          L 1 Reply Last reply 2 Aug 2020, 12:25
          2
          • M mrjj
            2 Aug 2020, 08:00

            Hi
            Its

            QFlags<QTextDocument::FindFlag> findFlags;
            
            L Offline
            L Offline
            lansing
            wrote on 2 Aug 2020, 12:25 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;
            }
            
            M 1 Reply Last reply 2 Aug 2020, 12:38
            0
            • L lansing
              2 Aug 2020, 12:25

              @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;
              }
              
              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 2 Aug 2020, 12:38 last edited by
              #6

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

              L 1 Reply Last reply 2 Aug 2020, 13:13
              1
              • M mrjj
                2 Aug 2020, 12:38

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

                L Offline
                L Offline
                lansing
                wrote on 2 Aug 2020, 13:13 last edited by
                #7

                @mrjj

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

                1 Reply Last reply
                0

                2/7

                1 Aug 2020, 23:22

                topic:navigator.unread, 5
                • Login

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