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

[SOLVED] How to compare value of a custom variable with constant in the *.pro file?



  • Could you please advise how does equals function work?

    I wont to use "equals ":https://qt-project.org/doc/qt-5.1/qmake/qmake-test-function-reference.html#equals-variablename-value function in the pro file:
    _equals(variablename, value)
    Tests whether variablename equals the string value.
    For example:
    TARGET = helloworld
    equals(TARGET, "helloworld") {
    message("The target assignment was successful.")
    }
    _

    So I've created following test pro file:
    @
    QT += core gui widgets

    TEMPLATE = app
    test_variable = 1

    message(test variable value = $$test_variable)

    equals(test_variable, "1")
    {
    message("1")
    }

    equals(test_variable, "2")
    {
    message("2")
    }
    @

    In the result I have :
    Project MESSAGE: test variable value = 1
    Project MESSAGE: 1
    Project MESSAGE: 2

    So both cases are occurred! I was trying equals($$(test_variable), "1") and it also doesn't work.

    How Can I compare custom variable value with any constant (or value of other variable)?



  • This code works. Note the curly brackets on the same line with equals.

    @
    test_variable = 1

    message(test variable value = $$test_variable)

    equals(test_variable, "1") { <---- here
    message("1")
    }

    equals(test_variable, "2") { <--- and here
    message("2")
    }
    @



  • Yes, this variant (the curly brackets on the same line with equals) works.
    I'm shocked...

    Thank you very much for your help!


Log in to reply