How to ignore wxCmdLineParser ? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
saifcoder
Experienced Solver
Experienced Solver
Posts: 80
Joined: Thu Nov 16, 2017 9:32 pm

How to ignore wxCmdLineParser ?

Post by saifcoder »

I want parse command arguments myself, i can get correctly argc and argv

Code: Select all

bool MyApp::OnInit()
{
    ... wxApp::argc ;
    ... wxApp::argv[2] ;
}
but i get wxCmdLineParser error message :
Unexpected paramter 'TestArg1'
Usage: minimal [/h] [--verbose]
/h, --help show this help message,
--verbose generate verbose log message.
i read many topics, google.., but i didn't find a way to ignore wxCmdLineParser

How to ignore command arguments Parser (wxCmdLineParser) please ?

Thanks,
Last edited by saifcoder on Wed Jun 06, 2018 9:57 pm, edited 1 time in total.
Debian 9 - GCC 6 - wxWidgets 3.x U
Win 10 - GCC 8 - wxWidgets 3.x U
Mac OS X 10.x - Clang - wxWidgets 3.x U
i am in love with WX. Yes.
User avatar
saifcoder
Experienced Solver
Experienced Solver
Posts: 80
Joined: Thu Nov 16, 2017 9:32 pm

Re: How to ignore command arguments Parser ?

Post by saifcoder »

its a GUI application ^_^
Debian 9 - GCC 6 - wxWidgets 3.x U
Win 10 - GCC 8 - wxWidgets 3.x U
Mac OS X 10.x - Clang - wxWidgets 3.x U
i am in love with WX. Yes.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to ignore command arguments Parser ?

Post by doublemax »

Don't call wxApp::OnInit() from inside your overloaded MyApp::OnInit().
Use the source, Luke!
User avatar
saifcoder
Experienced Solver
Experienced Solver
Posts: 80
Joined: Thu Nov 16, 2017 9:32 pm

Re: How to ignore command arguments Parser ?

Post by saifcoder »

Thank you for your replay Doublemax, but i didn't call wxApp::OnInit() from MyApp::OnInit() !

Where you see this call ? ^_^

I get this error because i run the app with test arguments (MyApp.exe ArgTest1 ArgTest2...), so the command arguments Parser (wxCmdLineParser) return unknow argument "ArgTest1"

I know, i can use the wxCmdLineParser... but is there i way to ignore this ? i want use my personal parser method !

Thank you,
Last edited by saifcoder on Wed Jun 06, 2018 9:58 pm, edited 1 time in total.
Debian 9 - GCC 6 - wxWidgets 3.x U
Win 10 - GCC 8 - wxWidgets 3.x U
Mac OS X 10.x - Clang - wxWidgets 3.x U
i am in love with WX. Yes.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to ignore command arguments Parser ?

Post by doublemax »

Where you see this call ? ^_^
I didn't see it, but it assumed is was there, because that's where the command line parsing happens. And removing it usually gets rid of the message.

Which platform and wxWidgets version are you using?

Try overriding wxAppConsole::OnCmdLineError(...)
http://docs.wxwidgets.org/trunk/classwx ... aac70e3144
Use the source, Luke!
User avatar
saifcoder
Experienced Solver
Experienced Solver
Posts: 80
Joined: Thu Nov 16, 2017 9:32 pm

Re: How to ignore wxCmdLineParser ?

Post by saifcoder »

I am using Github master branch (wxWidgets 3.1.1), on Windows (TDM GCC) right now, but i m sure the same result on Linux and Mac..

Code: Select all

class MyApp : public wxApp
{
    public:

	MyApp();
	~MyApp();
	virtual bool OnInit();
        virtual int OnExit();

	private:
		DECLARE_NO_COPY_CLASS(MyApp)
};

bool MyApp::OnInit()
{
	if (!wxApp::OnInit())
		return false;

	if (wxApp::argc > 1)
	{
		wxString Arg = wxApp::argv[2] ...
	}

    return true;
}
Thanks,
Debian 9 - GCC 6 - wxWidgets 3.x U
Win 10 - GCC 8 - wxWidgets 3.x U
Mac OS X 10.x - Clang - wxWidgets 3.x U
i am in love with WX. Yes.
User avatar
saifcoder
Experienced Solver
Experienced Solver
Posts: 80
Joined: Thu Nov 16, 2017 9:32 pm

Re: How to ignore wxCmdLineParser ?

Post by saifcoder »

Yes, wxAppConsole::OnCmdLineError() with true return did it, but after showing error message ! Waw!
Unexpected parameter 'TestArg1'
Then App continue in normal way because wxAppConsole::OnCmdLineError() return true, so how to completely prevent wxAppConsole::OnCmdLineError() to show error log ?
Last edited by saifcoder on Wed Jun 06, 2018 10:29 pm, edited 1 time in total.
Debian 9 - GCC 6 - wxWidgets 3.x U
Win 10 - GCC 8 - wxWidgets 3.x U
Mac OS X 10.x - Clang - wxWidgets 3.x U
i am in love with WX. Yes.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to ignore wxCmdLineParser ?

Post by doublemax »

Code: Select all

   if (!wxApp::OnInit())
      return false;
What's that? You said you didn't call it.

Set a breakpoint at the beginning of MyApp::OnInit and single step through it. I can't think of any other place where the command line parsing could happen.
Use the source, Luke!
User avatar
saifcoder
Experienced Solver
Experienced Solver
Posts: 80
Joined: Thu Nov 16, 2017 9:32 pm

Re: How to ignore wxCmdLineParser ?

Post by saifcoder »

Oh! Not me, but someone else*.. what a bad programmer.., but don't worry i remove it, now with OnCmdLineError() work correctly !

Thank you Doublemax, you save my day ^_^

*saifcoder
Debian 9 - GCC 6 - wxWidgets 3.x U
Win 10 - GCC 8 - wxWidgets 3.x U
Mac OS X 10.x - Clang - wxWidgets 3.x U
i am in love with WX. Yes.
Post Reply