Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Ambiguous conversion from one type to another



  • 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.


  • Lifetime Qt Champion

    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();



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


  • Lifetime Qt Champion

    @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.



  • 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.


  • Lifetime Qt Champion

    @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));
    


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


Log in to reply