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

QML errors on objects exposed to QML via root setContextProperty in 5.15.2



  • I get QML errors on objects exposed to QML via root setContextProperty in 5.15.2.

    The problem doesn't occur for me in 5.12.10.

    That said, the problem could be that I'm on SDK 11.1 and now on BigSur. I need to see if I can download the Xcode 10.15 SDK and retest it then follow up here..

    In the meantime, if there is a Mac OS user who is on 5.15.2 and has SDK 10.15, it might be worth testing root setContextProperty to see if it errors out for you, that way I could report a bug if it's a real problem.

    You'd need to try something like this in main.cpp:

    #include <QQmlContext>

    bool isMacOS;
    

    #ifdef Q_OS_MACOS
    isMacOS = true;
    #else
    isMacOS = false;
    #endif

    QQmlApplicationEngine engine;
    QQmlContext *rootContext = engine.rootContext();
    rootContext->setContextProperty("isMacOS", isMacOS);
    

    then try to use isMacOS in main.qml or in a Javascript file imported in main.qml.



  • Please feel free to close this if needed, since it's not a help question, per se. I just thought I would ask here if anyone else sees the problem on 10.15 SDK, since I'm not sure how easy it's going to be for me to get it installed in Big Sur.


  • Lifetime Qt Champion

    Hi,

    Wouldn't it be simpler to use the platform property ?



  • In regards to OS detection, you are correct. Yet the code I provided is "just for example" about how to generate the QML errors on Qt 5.15.2.

    My actual problem code is more complex than that, where I instantiate objects of 2 custom Qt classes and expose them to QML via root setContextProperty, and I get QML errors in 5.15.2.

    Thanks for the comment though - it is helpful for my future programming.


  • Lifetime Qt Champion

    Can you complete your example so we can reproduce the issue ?



  • It would also help to have the text of any errors, and indications of what code appears to trigger them.


  • Moderators

    @VStevenP
    can you show the actual error message ?

    also, do you have DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 enabled or something like that ?
    IIRC setContextProptery was supposed to become DEPRECATED sometime in the future



  • I am not able to recreate the problem as described so I will mark the topic as Solved. Thanks for your input.


Log in to reply