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

Error when initializing QStringList using initializer list.



  • Hi,

    I am using Qt 5.3.1 and Visual studio 2013. When I am initializing QStringList using initializer list then it is giving error.
    For ex. When I am doing this :

    QStringList {'a', 'b' , 'c'}; then I am getting following error:

    error C2440: '<function-style-cast>' : cannot convert from 'initializer-list' to 'QStringList'.

    It was working fine with Qt 5.2.

    Do any one is having idea about this?


  • Moderators

    Hi,

    Not sure but can you recompile with c++11 flag enabled.
    Add this to your .pro file
    @
    CONFIG += c++11
    @


  • Moderators

    Hi,

    Unfortunately Qt doesn't define a macro required to support initializer lists in MSVC 2013. Please add your vote to https://bugreports.qt-project.org/browse/QTBUG-39142 to have it fixed.

    As a temporary workaround, add this line to your .pro file and rerun qmake:
    @
    DEFINES += Q_COMPILER_INITIALIZER_LISTS
    @

    (Note: Be careful not to use this workaround if you have a compiler that doesn't support initializer lists)



  • Ok.

    Thanks a lot.

    Maahi



  • Hi,

    I tried but still its not working.
    Which .pro file needs to be changed ?

    Thanks,
    Maahi


  • Moderators

    Did you rerun qmake?



  • Yes, I followed the step.

    But there are a lot of .pro files. For ex. qt.pro , qtbase.pro. I made changes and configured again and run nmake. he whole process which I follow to build Qt binaries. Still it failed.

    Thanks
    Maahi


  • Moderators

    Ah, I meant the .pro file of your project! You didn't need to recompile the Qt binaries. Sorry I wasn't clear before...



  • Ok.
    The confusion is there becos there is no .pro file of my project. We use visual studio 2013 as compiler and use Qt (to support multi platform) integrated in it. So I configured Qt binaries for VS 2013. There was no problem when used Qt 5.2 but with Qt 5.3 there are issues (as mentioned in the link).

    That's why I reconfigured Qt. Do you have any idea ?

    Thanks,
    Maahi


  • Moderators

    Ok.

    • Use your original copy of Qt (before you reconfigured it)
    • Define the "Q_COMPILER_INITIALIZER_LISTS" in your project configuration. (I'm not sure how Visual Studio does that)

    As long as that macro is defined BEFORE any Qt headers are included, you can use initializer lists.



  • Thanks.

    Maahi


Log in to reply