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. Ambiguous conversion from one type to another

Ambiguous conversion from one type to another

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 1.2k 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.
  • O Offline
    O Offline
    Oreonan
    wrote on last edited by
    #1

    Hi,
    I try to convert a enum 32 bits to an enum 64 bits for a project where am contributor.
    My enum code is:

    enum TextToSpeechEvent: uint64_t
    {
    TTS_NONE = 0x0000000000000000,
    TTS_USER_LOGGEDIN = 0x0000000000000001,
    TTS_USER_LOGGEDOUT = 0x0000000000000002,
    TTS_USER_JOINED = 0x0000000000000004,
    TTS_USER_LEFT = 0x0000000000000008,
    TTS_USER_JOINED_SAME = 0x0000000000000010,
    TTS_USER_LEFT_SAME = 0x0000000000000020,
    TTS_USER_TEXTMSG_PRIVATE = 0x0000000000000040,
    TTS_USER_TEXTMSG_PRIVATE_SEND = 0x0000000000000080,
    TTS_USER_TEXTMSG_CHANNEL = 0x0000000000000100,
    TTS_USER_TEXTMSG_CHANNEL_SEND = 0x0000000000000200,
    TTS_USER_TEXTMSG_BROADCAST = 0x0000000000000400,
    TTS_USER_TEXTMSG_BROADCAST_SEND = 0x0000000000000800,

    TTS_SUBSCRIPTIONS_TEXTMSG_PRIVATE               = 0x0000000000001000,
    TTS_SUBSCRIPTIONS_TEXTMSG_CHANNEL               = 0x0000000000002000,
    TTS_SUBSCRIPTIONS_TEXTMSG_BROADCAST             = 0x0000000000004000,
    TTS_SUBSCRIPTIONS_VOICE                         = 0x0000000000008000,
    TTS_SUBSCRIPTIONS_VIDEO                         = 0x0000000000010000,
    TTS_SUBSCRIPTIONS_DESKTOP                       = 0x0000000000020000,
    TTS_SUBSCRIPTIONS_DESKTOPINPUT                  = 0x0000000000040000,
    TTS_SUBSCRIPTIONS_MEDIAFILE                     = 0x0000000000080000,
    
    TTS_SUBSCRIPTIONS_INTERCEPT_TEXTMSG_PRIVATE     = 0x0000000000100000,
    TTS_SUBSCRIPTIONS_INTERCEPT_TEXTMSG_CHANNEL     = 0x0000000000200000,
    TTS_SUBSCRIPTIONS_INTERCEPT_VOICE               = 0x0000000000400000,
    TTS_SUBSCRIPTIONS_INTERCEPT_VIDEO               = 0x0000000000800000,
    TTS_SUBSCRIPTIONS_INTERCEPT_DESKTOP             = 0x0000000001000000,
    TTS_SUBSCRIPTIONS_INTERCEPT_MEDIAFILE           = 0x0000000002000000,
    
    TTS_CLASSROOM_CHANMSG_TX                        = 0x0000000004000000,
    TTS_CLASSROOM_VOICE_TX                          = 0x0000000008000000,
    TTS_CLASSROOM_VIDEO_TX                          = 0x0000000010000000,
    TTS_CLASSROOM_DESKTOP_TX                        = 0x0000000020000000,
    TTS_CLASSROOM_MEDIAFILE_TX                      = 0x0000000040000000,
    
    TTS_FILE_ADD                                    = 0x0000000080000000,
    TTS_FILE_REMOVE                                 = 0x0000000100000000,
    
    TTS_MENU_ACTIONS                                = 0x0000000200000000,
    

    };

    typedef uint64_t TTSEvents;

    In another file I use this like this:

    TTSEvents events = ttSettings->value(SETTINGS_TTS_ACTIVEEVENTS, SETTINGS_TTS_ACTIVEEVENTS_DEFAULT).toULongLong();

    But I get the following error:

    preferencesdlg.cpp:573:106: error: conversion from ‘TextToSpeechEvent’ to ‘const QVariant’ is ambiguous
    TTSEvents events = ttSettings->value(SETTINGS_TTS_ACTIVEEVENTS, SETTINGS_TTS_ACTIVEEVENTS_DEFAULT).toULongLong();
    ^

    I made a lot of searches but I found nothing which fix this :(

    Have you an idea?
    Thanks in advance.

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

      Hi
      But where does QVariant come into play ?

      what if you do
      const TTSEvents events = ttSettings->value(SETTINGS_TTS_ACTIVEEVENTS, SETTINGS_TTS_ACTIVEEVENTS_DEFAULT).toULongLong();

      1 Reply Last reply
      0
      • O Offline
        O Offline
        Oreonan
        wrote on last edited by
        #3

        Hi and thanks for your answer,
        if I do this I have exactly the same error.

        mrjjM 1 Reply Last reply
        0
        • O Oreonan

          Hi and thanks for your answer,
          if I do this I have exactly the same error.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Oreonan

          Ok. its unclear from the code where the QVariant comes from.

          what is ttSettings ? QSettings ?

          what if you do
          auto test = ttSettings->value(SETTINGS_TTS_ACTIVEEVENTS, SETTINGS_TTS_ACTIVEEVENTS_DEFAULT).toULongLong();

          and then inspect test in the debugger what type does it show ?

          toULongLong() should make it not return a QVariant so i do wonder.

          1 Reply Last reply
          0
          • O Offline
            O Offline
            Oreonan
            wrote on last edited by
            #5

            Yes, ttSettings is a QSettings. We use value return by the line to select items in a QModel after with following line:
            m_ttsmodel->setTTSEvents(events);
            If it can be usefull, here is an old code with a 32 bits enum which it was working:
            enum TextToSpeechEvent
            {
            TTS_NONE = 0x00000000,
            TTS_USER_LOGGEDIN = 0x00000001,
            TTS_USER_LOGGEDOUT = 0x00000002,
            TTS_USER_JOINED = 0x00000004,
            TTS_USER_LEFT = 0x00000008,
            TTS_USER_JOINED_SAME = 0x00000010,
            TTS_USER_LEFT_SAME = 0x00000020,
            TTS_USER_TEXTMSG_PRIVATE = 0x00000040,
            TTS_USER_TEXTMSG_PRIVATE_SEND = 0x00000080,
            TTS_USER_TEXTMSG_CHANNEL = 0x00000100,
            TTS_USER_TEXTMSG_CHANNEL_SEND = 0x00000200,
            TTS_USER_TEXTMSG_BROADCAST = 0x00000400,
            TTS_USER_TEXTMSG_BROADCAST_SEND = 0x00000800,
            }
            typedef uint32_t TTSEvents;
            And:
            TTSEvents events = ttSettings->value(SETTINGS_TTS_ACTIVEEVENTS, SETTINGS_TTS_ACTIVEEVENTS_DEFAULT).toUInt();
            I don't understand why a 32 bits enum works perfectly but not after migrate to 64 bits enum.

            1 Reply Last reply
            0
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Oreonan said in Ambiguous conversion from one type to another:

              I don't understand why a 32 bits enum works perfectly but not after migrate to 64 bits enum.

              The compiler tells you why - QVariant has no overload for uint64_t so you have to do a proper cast to e.g. qulonglong (quint64) which is unsigned long long and not uint64_t

              uint64_t blub = 0;
              QVariant v = QVariant(blub);
              QVariant v2 = QVariant(quint64(blub));
              

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              2
              • O Offline
                O Offline
                Oreonan
                wrote on last edited by
                #7

                I finally replaced uint64_t by quint64 when creating enum. After this, I can use toUint() function.
                Thanks for your help :)

                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