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 interprets "false" as "true"

Bool interprets "false" as "true"

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 416 Views 3 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.
  • Q Offline
    Q Offline
    qtnoob420
    wrote on last edited by
    #1

    i am getting my checkboxes filled like:

    checkbox_1.setChecked(bool(feature["checkbox_1"]))
    

    and after they are getting checked/unchecked i save the changes with:

    feature["checkbox_1"] = checkbox_1.isChecked()
    

    now the problem...
    before the values from database are "x" for checked and "NULL" for unchecked. i should try to keep these values in the best case, but im not sure if and how this is possible.
    after checked/unchecked the checkboxes their values from the second command are "true" and "false". when i now uncheck one of the boxes the first command interprets "true" and "false" both as "checked"

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      It's up to you to "translate" these two non Boolean values to Boolean back and forth.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Q 1 Reply Last reply
      3
      • SGaistS SGaist

        Hi,

        It's up to you to "translate" these two non Boolean values to Boolean back and forth.

        Q Offline
        Q Offline
        qtnoob420
        wrote on last edited by
        #3

        @SGaist oh okay. can you please give me an example on that?

        jsulmJ 1 Reply Last reply
        0
        • Q qtnoob420

          @SGaist oh okay. can you please give me an example on that?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @qtnoob420 Is really not that hard:

          checked = False
          if feature["checkbox_1"] == "x":
              checked = True
          

          Or shorter:

          checked = feature["checkbox_1"] == "x"
          

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          Q 1 Reply Last reply
          4
          • jsulmJ jsulm

            @qtnoob420 Is really not that hard:

            checked = False
            if feature["checkbox_1"] == "x":
                checked = True
            

            Or shorter:

            checked = feature["checkbox_1"] == "x"
            
            Q Offline
            Q Offline
            qtnoob420
            wrote on last edited by
            #5

            @jsulm perfect thanks :)

            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