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. Bool Qlist check if every item in list is true

Bool Qlist check if every item in list is true

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 4 Posters 2.3k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    ARASHz4
    wrote on last edited by
    #1

    hi
    i have a list of bool

    QList<bool> check;
    

    how can i check all items is true?

    J.HilkJ 1 Reply Last reply
    0
    • JohanSoloJ Offline
      JohanSoloJ Offline
      JohanSolo
      wrote on last edited by
      #2

      I'd go with std::all_of.

      `They did not know it was impossible, so they did it.'
      -- Mark Twain

      1 Reply Last reply
      2
      • A ARASHz4

        hi
        i have a list of bool

        QList<bool> check;
        

        how can i check all items is true?

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @ARASHz4 usually by iterating over your list and checking.

        luckilyfor you, QList has a predefined function that will do exactly what you want it to, without doing anyting yourself.

        bool QList::contains(const T &value) const

        QList<bool> check;
        bool alltrue = !check.contains(false);
        

        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        7
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          std::all_of(check.constBegin(),check.constEnd(),[](bool val){return val;});

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          5

          • Login

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