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]How to convert QVariant to Qt::CheckState enum value?
Forum Updated to NodeBB v4.3 + New Features

[Solved]How to convert QVariant to Qt::CheckState enum value?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 9.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.
  • P Offline
    P Offline
    phamtv
    wrote on last edited by
    #1

    I tried this but it does not work...

    @
    // model is a subclass of QFileSystemModel
    Qt::CheckState state = static_castQt::CheckState(model->data(index, Qt::CheckStateRole));
    @

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      Try this:

      @
      Qt::CheckState state = model->data(index, Qt::CheckStateRole).valueQt::CheckState();
      @

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • P Offline
        P Offline
        phamtv
        wrote on last edited by
        #3

        Thanks ZapB... but your repsonse gave me an error
        @
        error: ‘qt_metatype_id’ is not a member of ‘QMetaTypeIdQt::CheckState’
        @

        however, I tried the following and it works...
        @
        Qt::CheckState state = static_castQt::CheckState(model->data(index, Qt::CheckStateRole).toUInt());
        @

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          ZapB
          wrote on last edited by
          #4

          Ah yes of course. Sorry for the false lead. Brain not working today.

          Nokia Certified Qt Specialist
          Interested in hearing about Qt related work

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tobias.hunger
            wrote on last edited by
            #5

            You can try to cast the value to an int and store that (casting it back when reading it). Alternatively you can register the type with the Qt metatype system yourself. Check the docs:-)

            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