Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Window not invoking/not displaying when called from inside if block
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 473 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    anuj nogja
    wrote on last edited by
    #1

    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;
    w1.show();
    else
    Window2 w2;
    w2.show();

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

    Thanks,
    Anuj

    jsulmJ J.HilkJ 2 Replies Last reply
    0
    • A anuj nogja

      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;
      w1.show();
      else
      Window2 w2;
      w2.show();

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

      Thanks,
      Anuj

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

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

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A anuj nogja

        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;
        w1.show();
        else
        Window2 w2;
        w2.show();

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

        Thanks,
        Anuj

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        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)
        {
            w1.show();
        }else{
            w2.show();
        }
        

        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        2

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved