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. [SOLVED] QSqlTableView translation of MySQL TINYINT(1) type
QtWS25 Last Chance

[SOLVED] QSqlTableView translation of MySQL TINYINT(1) type

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.5k 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.
  • C Offline
    C Offline
    Chardrazle
    wrote on 27 Aug 2014, 15:29 last edited by
    #1

    In MySQL the Boolean type is synonomous with the TINYINT (1) type.

    When a query returns rows with a column of this type, the Qt SQL framework translates it to a QVariant::Int type (or potentially QVariant:Unsigned, see QTBUG-14073).

    This is then displayed by a QSqlTableView as "0" or "1".

    Typically, if this column was designed to represent a boolean value, a checkbox widget would be used to edit the column. E.g. via direct in-table editing, or via QDataWidgetMapper.

    However, after editing, the "user" property of the checkbox widget will set the column back as QVariant::Bool. This will then show up in the table as "true" or "false".

    Ideally, I would prefer to always see the value as "true" or "false". Is there a way to ensure the initial table query appears this way? I.e. treats the TINYINT (of size 1) as boolean.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 27 Aug 2014, 19:59 last edited by
      #2

      Hi and welcome to devnet,

      You could use a QIdentityProxyModel and return true or false based on the content of the database for this column.

      Hope it helps

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

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Chardrazle
        wrote on 28 Aug 2014, 09:49 last edited by
        #3

        Thanks, that's exactly what I was looking for.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 28 Aug 2014, 21:23 last edited by
          #4

          You're welcome !

          Since you have your view running, please update the thread title preening [solved] so other forum users may know a solution has been found :)

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

          1 Reply Last reply
          0

          2/4

          27 Aug 2014, 19:59

          • Login

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