Important: Please read the Qt Code of Conduct -

Window not invoking/not displaying when called from inside if block

  • Hello All,
    There is one requirement to call two different windows based upon condition placed in if block like..
    if(argc == 2 AND argv[1] = 1)
    Window1 w1;;
    Window2 w2;;

    If i remove the if-else condition then Window is getting invoked and displaying also.
    But when putting the if block then its going in infinite loop and nothing getting displayed.
    Kindly suggest how this problem can be solved..


  • Lifetime Qt Champion

    @anuj-nogja Please show whole main() content.
    Also what does the constructor of the window which is not showing do? Can you show its constructor?

  • Moderators

    hi @anuj-nogja ,
    if I see that correctly, than you create the Window1 w1; and the Window2 w2; objects inside the if-brackets those will be destoyed as soon as the the bracket closes.

    try this:

    Window1 w1;
    Window2 w2;
    if(argc == 2 AND argv[1] = 1)

Log in to reply