Unsolved Invoking the window "Help Window" from command line
-
Hello All,
In my project, I have created a "Help" button in MainWindow. When this button is clicked, a new window is opened and help related content is available in this window. It is working fine.The requirement is when user enters " ./<project-name> -h" from command line then that only help window should get invoked (main window where other project stuff is also present should not get invoked) so that user can see help page.
Kindly suggest the approach...
Thanks..Regards,
Anuj -
@anuj-nogja said in Invoking the window "Help Window" from command line:
./<project-name> -h
Sounds like an unusual approach.
Usually "./<project-name> -h" shows help in the terminal not in a window.
But if you really want to implement it this way then simply check command line parameters and if -h is passed you do not create your main window but only this help window. -
@jsulm Hi,
While calling help window as -h condition is true, help window is not getting displayed. (Its going in some infinite loop).
Code i have written is:
if((argc==2) && (strcmp(argv[1],"-h")==0))
{
HelpWindow help;
help.show()
}Kindly suggest..
-
@anuj-nogja Please show whole content of your main()
-
@anuj-nogja As @J-Hilk pointeg out here https://forum.qt.io/topic/87579/window-not-invoking-not-displaying-when-called-from-inside-if-block/3 you're creating the window instances inside if {} else {} blocks. That means as soon es if {} or else {} block is left your windows are destroyed.
-
@anuj-nogja
Ifhelp
were aQDialog
, you could also gohelp.exec()
instead ofhelp.show()
and your code would work as-is.@jsulm
I'd like to understand one thing about this commonly-reported problem posters have, bearing in mind that I use Python not C++ so I do not encounter stack variable/out of scope.When he goes
help.show()
, "in principle" that shows the window (though I do understand there is probably delay till message loop gets pumped).When his code then hits the
}
close scope, that destructshelp
. Do I presume that if a shown window/dialog is destructed, Qt does an implicit "hide"/"close" on it first? -
@JonB I don't know whether Qt does a hide first or simply removes the window. I'm not even sure whether the dialog is shown at all in this case as show() is asynchronous/non blocking and the dialog is destroyed just after calling show().
-
@jsulm
Yep, OK. I sort of expected the code to "crash" in the message loop pump, in that there would be a pending message to "show that window" but when processed asynchronously Qt would find no such window in existence. I guess it just ignores a message for a window which does not exist....